在图片处理的过程中,经常会需要对读入的图片进行变换;
图片读入时基本上以uint8格式为主,对图片进行处理(灰度图,归一化等)后通常会被转换为float格式
当想要再次查看图片时最好先将图片转换为uint8格式,否则容易出现各种奇怪的问题
from PIL import Image
from pylab import *
im = array(Image.open("04.jpg"))
print(im.dtype) #unit8
im3 = 255.0 * (im/255.0)**2 # 将图像像素值变换到100...200 区间
print(im3.dtype) #float64
pil_im = Image.fromarray(uint8(im3))
# 通过PIL中的fromarray方法将图片转换为uint8格式(此时的pil_im为image对象)
imshow(pil_im)
show()