0
我用黑色线条绘制了一个相对复杂的图像,我想将背景颜色从白色更改为随机颜色。PIL在不影响边缘的情况下替换颜色
使用PIL我用颜色替换所有非黑色像素:
pixels = output.getdata()
newPixels = []
for pixel in pixels:
if pixel[0] != 0 and pixel[1] != 0 and pixel[2] != 0:
newPixels.append(color)
else:
newPixels.append(pixel)
output.putdata(newPixels)
这使得该行的所有成锯齿状我更换边缘平滑不完全是黑色的像素为好。任何解决方案
你能向我们展示的形象呢?如果它纯粹是灰度,我有一个想法。 – Kevin 2014-10-07 15:40:50
边缘检测图像,然后避免更改这些区域中的像素。 – 2014-10-07 15:44:06