我们正在使用Image magik并使用python编程语言。 我们已经能够对颜色进行一些更改,但它不适用于每个图像,有时整个图像会改变颜色,而不仅仅是所需的部分。 我们只想更改颜色,不想添加任何效果 这些是我们使用的2个代码。 第一:
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()
和第二个。
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()
答案 0 :(得分:0)
对于表达式lambda i: i > 100 and 300
- 如果i大于100,则返回300,否则返回False
。
表达式为:lambda i: i < 100 and 300
- 如果i小于100,则返回300,否则返回False
。
这是你的意图吗?
根据我对您的代码要求的理解,您可能希望将第一个替换为lambda i: i > 100 and i or 300
,将第二个替换为lambda i: i < 100 and i or 300