开发者

Python : Making a negative image of a RGB picture

I'v开发者_高级运维e been fiddling around with Python for hours now, trying to figure out how to turn my colored image into a color negative and I just can't seem to be able to figure it out..

I've imported PIL and Image from PIL andI know that I need to do something similar to (255.0 - red, 255.0 - green, 255.0 - blue) in order to negate the image, but I just can't seem to be able to figure out how to incorporate that into my 'for' loop.

I'm really not that good at python at all, and any help would really be appreciated =/

thankyou in advance :)


inverted = Image.eval(original, lambda(x):255-x)


I'm not, myself, a PIL user, but a quick search of the documentation turned up an invert function.

ImageOps.invert(image) => image
    Invert (negate) the image.

Perhaps that's what you're looking for?


I realize this thread is pretty old but, I came across this in my travels and thought it was relevant, hope it's of some help.

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜