我今天在Hacker News 上看到一篇文章,该文章展示了如何将恒定基色的图像与affine transform 混合。这篇文章是 William Chargin 的 Making thumbnails fast,它是关于提高图像处理性能的。其中提到的源代码在affine transforms on PIL images。
这是一个演示,从灰度Lena 图像开始调整为 231x231 像素。选择这张图片是因为它是“自 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