1. 程式人生 > >用python去除圖片中指定顏色的畫素

用python去除圖片中指定顏色的畫素

用python去除圖片白色畫素

需要python和pil

from PIL import Image
import numpy as np
import cv2
img2 = Image.open('./Amazing_COL_2Fix.bmp')
img1 = Image.open('./Amazing_RGB_2L.bmp')
# img1 = img1.convert('RGBA')
img2 = img2.convert('RGBA')
pixdata = img2.load()
for y in range(img2.size[1]):
    for x in range(img2.size[0]):
        if pixdata[x,y][0]==0 and pixdata[x,y][1]==0 and pixdata[x,y][2]<256:
           pixdata[x, y] = (255, 255, 255,0)

img2.show()