本文实例讲述了python实现去除图片中指定颜色的像素功能。分享给大家供大家参考,具体如下:
这里用python去除图片白色像素
需要python和pil
1
2
3
4
5
6
7
8
9
10
11
12
13
|
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() |
修改前的图片:
修改后的图片:
希望本文所述对大家python程序设计有所帮助。
原文链接:https://blog.csdn.net/qq_36955294/article/details/82953224