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