开发者

how to change the look of an image according to the season we like

We are working with Image magik and using python programming language. We have been able to make some changes to the colours but it does not work for every image and at other times the entire image changes colour not just the required portions . We only want to change the colours and don't want to add any effects These are the 2 codes we have used. first:

import Image
import ImageEnhance
img = Image.open( 'image.jpg')
img = img.convert('RGBA')
r, g, b, alpha = img.split()
selection = r.point(lambda i: i > 100 and 300)
selection.save( "autmask.png")
r.paste(g, None, selection)
img = Image.merge( "RGBA", (r, b, g, alpha))
img.save( "newclr.png")
img.show()

and the second.

import Image

# split the image into individual bands
im = Image.open('image.jpg')
im.convert("RGB")
source = im.split()
R, G, B = 0, 1, 2
# select regions where red is less than 100
mask = source[B].point(lambda i: i < 100 and 300)
# process the green band
out = source[G].point(lambda i: i * 2.5)

开发者_运维技巧# paste the processed band back, but only where red was < 100
source[G].paste(out, None, mask)

# build a new multiband image
im = Image.merge(im.mode, source)
im.save( "newimage.png")
im.show()


For the expressions lambda i: i > 100 and 300 - It will return 300 if i is greater than 100 otherwise it will return False.

For the expression: lambda i: i < 100 and 300 - It will return 300 if i is lesser than 100 otherwise it will return False.

This is what you intended?

From what I understand of your code requirement, you may want to replace the first one with lambda i: i > 100 and i or 300 and second one with lambda i: i < 100 and i or 300

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜