import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
image_origin = Image.open('D:\Desktop\low-light image\Lenna.jpg')
plt.figure(figsize=(10,25))#画布大小
plt.subplot(5,4,1)# 使用plt.subplot来创建小图. plt.subplot(221)表示将整个图像窗口分为2行2列, 当前位置为1.
# CMYK 减色彩色模式,当阳光照射到一个物体上,物体会吸收一部分光线,剩下的光线进行反射,反射光就是物体的颜色----减色彩色模式。
image_cmyk = image_origin.convert("CMYK")
plt.imshow(image_cmyk)
plt.title('Original CMYK')
image_temp = np.array(image_cmyk)
image_c = image_temp[:,:,0]#青
image_m = image_temp[:,:,1]#洋红
image_y = image_temp[:,:,2]#黄
image_k = image_temp[:,:,3]#黑
plt.subplot(5,4,5),plt.imshow(image_c,'gray'),plt.title('Cyan')
plt.subplot(5,4,6),plt.imshow(image_m,"gray"),plt.title('Magenta')
plt.subplot(5,4,7),plt.imshow(image_y,"gray"),plt.title('Yellow')
plt.subplot(5,4,8),plt.imshow(image_k,"gray"),plt.title("Black")
# Show RGB channels
image_rgb = image_origin.convert("RGB")
image_rgb = np.array(image_rgb)
plt.subplot(5,4, 9),plt.imshow(image_rgb[:,:,0],'gray'),plt.title('Red')
plt.subplot(5,4,10),plt.imshow(image_rgb[:,:,1],'gray'),plt.title('Green')
plt.subplot(5,4,11),plt.imshow(image_rgb[:,:,2],'gray'),plt.title('Blue')
# Show HSI channels
image_hsi = image_origin.convert("HSV")
image_hsi = np.array(image_hsi)
plt.subplot(5,4,13),plt.imshow(image_hsi[:,:,0],"gray"),plt.title("Hue")
plt.subplot(5,4,14),plt.imshow(image_hsi[:,:,1],"gray"),plt.title('Saturation')
plt.subplot(5,4,15),plt.imshow(image_hsi[:,:,2],'gray'),plt.title('Intensity')
plt.tight_layout()#自动调节plt.subplot的间距
plt.show()
python色彩变换CMYK,RGB,HSI
最新推荐文章于 2023-07-01 13:13:41 发布