python获取颜色范围

python获取颜色范围

img_src = Image.open('testluban.jpg')
img_size=img_src.size;
img_width=img_size[0];
img_height=img_size[1];
# 转换图片的模式为RGBA
img_src = img_src.convert('RGB')
 
# 获得文字图片的每个像素点
src_strlist = img_src.load()

 
# 寻找图片中白色点 并且获得他的min max
wattr=[];
hattr=[];
for w in range(img_width):
    for h in range(img_height):
        if src_strlist[w,h][0]>=240 and src_strlist[w,h][1]>=240 and src_strlist[w,h][2]>=240:
            wattr.append(w)    
            hattr.append(h)    
            

print(min(wattr),min(hattr))
print(max(wattr),max(hattr))

 

posted @ 2021-09-28 13:46  newmiracle宇宙  阅读(498)  评论(0编辑  收藏  举报