我今天在
Hacker News发现了一篇文章,其中展示了如何通过恒定的基色与
affine transform混合图像.文章是由William Chargin撰写的
Making thumbnails fast及其改进的图像处理性能.其中提到的源代码是
affine transforms on PIL images.
这是一个演示,从调整大小为231×231像素的灰度Lena图像开始.选择该图像是因为它是“自1973年以来广泛用于图像处理领域的标准测试图像”.
from PIL import Image
from transforms import RGBTransform # from source code mentioned above
lena = Image.open("lena.png")
lena = lena.convert('RGB') # ensure image has 3 channels
lena
red = RGBTransform().mix_with((255, 0, 0),factor=.30).applied_to(lena)
red
green = RGBTransform().mix_with((0, 255, 0),factor=.30).applied_to(lena)
green
blue = RGBTransform().mix_with((0, 0, 255),factor=.30).applied_to(lena)
blue