问题描述
|
大家好,我已经摆弄了几个小时的Python,试图弄清楚如何将彩色图像变成彩色负片,但我似乎无法弄清楚。
我已经从PIL导入了PIL和图像,并且我知道我需要做一些类似于(255.0-红色,255.0-绿色,255.0-蓝色)的操作来消除图像,但是我似乎无法能够弄清楚如何将其合并到我的“ for”循环中。
我真的一点也不擅长python,真的很感谢任何帮助= /
先感谢您 :)
解决方法
inverted = Image.eval(original,lambda(x):255-x)
, 我自己不是PIL用户,但是快速搜索文档后便显示了invert
函数。
ImageOps.invert(image) => image
Invert (negate) the image.
也许这就是您要寻找的?
, 我意识到这个线程已经很老了,但是我在旅行中遇到了这个问题,并认为它是相关的,希望对您有所帮助。
def invert():
picture=makePicture(\"C:/somepic.png\")
for px in getPixels(picture):
r=getRed(px)
g=getGreen(px)
b=getBlue(px)
newColour=makeColor(255-r,255-g,255-b)
setColor(px,newColour)
repaint(picture)
, for r,row in enumerate(myPicture):
for c,value in enumerate(row):
myPicture[r][c] = invert(value)