Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:图像显示中的像素值?_Python_Image_Numpy_Pixels - Fatal编程技术网

Python:图像显示中的像素值?

Python:图像显示中的像素值?,python,image,numpy,pixels,Python,Image,Numpy,Pixels,使用任何numpy、scikit图像库,我都可以轻松地将图像作为数据数组加载和显示。但是,我想要某种显示,在那里我可以在图像周围移动光标,并查看当前像素的索引及其灰度(或RGB)值,例如:(213,47:178)或(213,47:122,10205)-这些值当然会随着光标的移动而不断变化 有没有一个简单的方法可以做到这一点?哦:我正在使用Linux,但我的学生将使用Windows,所以我希望有一个跨平台的解决方案。我正在使用tkinter来显示和PIL来阅读任何类型的图像。这是一个veeerry

使用任何numpy、scikit图像库,我都可以轻松地将图像作为数据数组加载和显示。但是,我想要某种显示,在那里我可以在图像周围移动光标,并查看当前像素的索引及其灰度(或RGB)值,例如:(213,47:178)或(213,47:122,10205)-这些值当然会随着光标的移动而不断变化


有没有一个简单的方法可以做到这一点?哦:我正在使用Linux,但我的学生将使用Windows,所以我希望有一个跨平台的解决方案。

我正在使用
tkinter
来显示和
PIL
来阅读任何类型的图像。这是一个veeerryyy慢速解决方案

def pil2tkinter_image(img_path, master = None, *args, **kw):
    import tkinter, PIL.Image
    img = PIL.Image.open(img_path)
    x0, y0, width, height = img.getbbox()
    l = []
    for y in range(y0, height):
        l.append('{')
        for x in range(x0, width):
            l.append('#%02X%02X%02X' % img.getpixel((x, y))[:3])
        l.append('}')
    data = ' '.join(l) # slow part
    pi = tkinter.PhotoImage(master = master, *args, **kw)
    pi.put(data, (0,0))
    return pi
函数
pil2tkinter_image
获取任何类型的图像的路径,png、bmp、jpg、gif,并从中创建一个tkinter照片图像


您可以将此图像嵌入tkinter小部件中,并使用鼠标事件读取像素值。

我使用
tkinter
显示,使用
PIL
读取任何类型的图像。这是一个veeerryyy慢速解决方案

def pil2tkinter_image(img_path, master = None, *args, **kw):
    import tkinter, PIL.Image
    img = PIL.Image.open(img_path)
    x0, y0, width, height = img.getbbox()
    l = []
    for y in range(y0, height):
        l.append('{')
        for x in range(x0, width):
            l.append('#%02X%02X%02X' % img.getpixel((x, y))[:3])
        l.append('}')
    data = ' '.join(l) # slow part
    pi = tkinter.PhotoImage(master = master, *args, **kw)
    pi.put(data, (0,0))
    return pi
函数
pil2tkinter_image
获取任何类型的图像的路径,png、bmp、jpg、gif,并从中创建一个tkinter照片图像


您可以将此图像嵌入tkinter小部件中,并使用鼠标事件读取像素值。

使用
matplotlib
查看链接问题和api示例此图像的可能副本非常容易使用
matplotlib
查看链接问题和api示例