编程语言
首页 > 编程语言> > python获取图片中某个像素的坐标

python获取图片中某个像素的坐标

作者:互联网

python获取图片中某个像素的坐标

 

from PIL import Image

img = Image.open('zhaose.png')
pixels = img.load() 
width, height = img.size

for x in range(width):
    for y in range(height):
        r, g, b = pixels[x, y]
        
        # in case your image has an alpha channel
        # r, g, b, a = pixels[x, y]
        if(r==218 and g==196 and b==153):
            print(x, y, f"#{r:02x}{g:02x}{b:02x}")

 

标签:img,python,02x,height,width,坐标,像素,pixels
来源: https://www.cnblogs.com/newmiracle/p/16590166.html