实验代码:
from PIL import Image#读图片 转化图像
import matplotlib
matplotlib.use('Agg')#为了能保存图片
import matplotlib.pyplot as plt#显示图片
mode = ['1', 'L', 'P', 'RGB', 'RGBA', 'CMYK', 'YCbCr', 'I', 'F']
img = Image.open('5.jpg')
plt.imshow(img)
plt.show()
print('the original finished!')
for one_mode in mode:
img = Image.open('5.jpg')
img = img.convert(one_mode)
plt.imshow(img)
plt.show()
plt.savefig(one_mode + '.jpg')
print(one_mode + ' mode convert finished!')
the original picture:
convert('1'):
convert('L'):
convert('P'):
convert('RGB'):
convert('RGBA'):
convert('CMYK'):
convert('YCbCr'):
convert('I'):
convert('F'):
该博客以 Python图像处理库PIL-convert()函数(https://blog.csdn.net/chris_pei/article/details/78261922)博客作为依据,来讨论convert()函数的作用,观察图片(所以会有错误)现在能大略知道,
'F', 'l', 'L'是对原图片做灰度值转化;
’1‘在上述博客讲得挺好的,当成了黑色像素的密度处理;
除'P'外,其余方式都对原多彩图片没做改动。