
PIL有九种不同模式: 1,L,P,RGB,RGBA,CMYK,YCbCr,I,F。
为二值图像,非黑即白。每个像素用8个bit表示,0表示黑,255表示白。
代码示例
from PIL import Image
def convert_1():
    image = Image.open("D:/pytorch_code/pytorch_study/fusion_datasets/1.jpg")
    image_1 = image.convert('1')
    image.show()
    image_1.show()
转化为灰度图像,每个像素用8个bit表示,0表示黑,255表示白,其他数字表示不同的灰度。
转换公式:L = R * 299/1000 + G * 587/1000+ B * 114/1000。
代码示例
from PIL import Image
def convert_L():
    image = Image.open("D:/pytorch_code/pytorch_study/fusion_datasets/1.jpg")
    image_L = image.convert('L')
    image.show()
    image_L.show()
对比上图可以发现,1模式得到图顿点很多,有点像高斯噪声的感觉,而L模式更平滑一些。
代码示例
from PIL import Image
def convert_P():
    image = Image.open("D:/pytorch_code/pytorch_study/fusion_datasets/1.jpg")
    image_P = image.convert('P')
    image.show()
    image_P.show()