def CMYKInvert(img) :
return Image.merge(img.mode, [ImageOps.invert(b.convert('L')) for b in img.split()])
14
from PIL import Image
img = Image.open("archive.extension")
pixels = img.load()
for i in range(img.size[0]):
for j in range(img.size[1]):
x,y,z = pixels[i,j][0],pixels[i,j][1],pixels[i,j][2]
x,y,z = abs(x-255), abs(y-255), abs(z-255)
pixels[i,j] = (x,y,z)
img.show()
5 回答
从文档中尝试以下内容:http://effbot.org/imagingbook/imageops.htm
注意:“ImageOps模块包含许多'现成的'图像处理操作 . 这个模块有点实验性,大多数操作员只能处理L和RGB图像 . ”
如果图像是RGBA透明,这将失败......这应该工作:
对于使用"1"模式的图像的任何人(即1位像素,黑色和白色,每个字节存储一个像素 - see docs),您需要在调用
PIL.ImageOps.invert
之前将其转换为"L"模式 .从而:
如果有人正在反转
CMYK
图像,PIL和Pillow的当前实现使用这个方便的功能(基本上是上面Greg Sadetsky的帖子的扩展)来使用各个乐队:`