2 回答

TA貢獻(xiàn)1856條經(jīng)驗 獲得超17個贊
此模板應(yīng)該使您走上正確的道路:
from PIL import image
picture = Image.open(path_to_picture)
width, height = picture.size
for x in range(width):
for y in range(height):
current_color = picture.getpixel( (x,y) )
if current_color[0:3]!=(255,255,255):
picture.putpixel( (x,y), (***, ***,***) + (current_color[-1],))
picture.save(path_to_new_picture)
請注意,此處getpixel()將返回一個元組,其中包含給定像素的RGBA值。在此示例中,我假設(shè)您保留了alpha值,并且只是修改了當(dāng)前像素的RGB值。

TA貢獻(xiàn)1818條經(jīng)驗 獲得超11個贊
您需要遍歷圖像中的每個像素。
...imgA!= [255,255,255]
將始終返回true,因為您正在將(512,512,3)nd.array與(3,)nd.array進(jìn)行比較
即使您的圖像不是由numpy矩陣構(gòu)建的,這一點仍然適用。如果遇到性能問題,請使用cython加快循環(huán)速度。
添加回答
舉報