from PIL import Image
from pylab import *
im = array(Image.open('/Users/mubai/Pictures/IMG_0053.png').convert('L'))
# 对图像进行反相处理
im2 = 255 - im
# 将图像像素值变换到100-200区间
im3 = (100.0/255) * im + 100
# 将图像像素值求平方后得到的图像
im4 = 255.0 * (im/255.0) ** 2
# 查看图像中的最小和最大像素值
print(int(im.min()), int(im.max()))
# array()的相反操作
pill_im = Image.fromarray(im)
# 非uint8类型的需要先转换类型
pill_im = Image.fromarray(uint8(im3))
|
|