소스 뷰어
from matplotlib import pyplot as plt

# 이미지 읽기 
img = plt.imread( 'messi5.jpg' )

# split the image into 3 channel data
red  = img[:, :, 0]  # blue channel data
green = img[:, :, 1]  # green channel data
blue   = img[:, :, 2]  # red channel data

plt.imshow( img  )
plt.show()
No description has been provided for this image
plt.imshow( red, cmap="gray" )
plt.show()
No description has been provided for this image
import numpy as np
shape = red.shape

red_img = np.stack( ( red, np.zeros( shape ), np.zeros( shape ) ), axis=2 )

red_img_uint8 = red_img.astype( np.uint8 )

print( "red_img.dtype = ", red_img.dtype )
print( "red_img_uint8.dtype = ", red_img_uint8.dtype )

# 이미지 저장 하기 
#plt.imsave( 'my_messi_red.png', red_img )  # 에러 발생 
plt.imsave( 'my_messi_red.png', red_img.astype(np.uint8) )
# 이미지 출력하기 
#plt.imshow( red_img ) # 이상하게 출력됨.
plt.imshow( red_img_uint8 )
plt.show()
red_img.dtype =  float64
red_img_uint8.dtype =  uint8
No description has been provided for this image