我有一张PNG图像和一个黑白面具.这篇文章(https://note.nkmk.me/en/python-pillow-putalpha/)演示了如何使用putalpha()
发送图像的Alpha通道,以便遮罩区域变得透明.我想知道Pillow中是否有函数可以真正将遮罩区域的RGB值更改为全部255?
下面是一个例子.结果图像应该具有实际RGB值为255的所有白色区域,而不是仅将Alpha设置为0.
Updated question个
(当我try 使用ImageChops
时,遇到了一些错误:
下面是我运行的代码:
from PIL import Image, ImageChops
im = Image.open('lena.jpg')
mask = Image.open('mask_circle.png')
print(im, mask)
darker = ImageChops.darker(im, mask)
darker.save('darker.png')
我得到的错误是:
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=400x225 at 0x24725330BF0> <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=400x225 at 0x24724F2CD40>
Traceback (most recent call last):
File "E:\test.py", line 7, in <module>
darker = ImageChops.darker(im, mask)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\...\Local\Programs\Python\Python312\Lib\site-packages\PIL\ImageChops.py", line 81, in darker
return image1._new(image1.im.chop_darker(image2.im))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: images do not match