[英]Python: Pixel values in image display?
Using any of the numpy, scikit-image libraries, I can easily load and display an image as an ndarray. 使用任何numpy,scikit-image库,我都可以轻松加载图像并将其显示为ndarray。 However, I'd like some sort of display where I can move the cursor around the image, and see the indices of the current pixel, and its gray (or RGB) values, for example: (213,47: 178) or (213,47: 122,10,205) - these values of course constantly changing as the cursor moves.
但是,我需要某种显示器,可以在图像上移动光标,并查看当前像素的索引及其灰色(或RGB)值,例如:(213,47:178)或( 213,47:122,10,205)-这些值当然会随着光标的移动而不断变化。
Is there an easy way to do this? 是否有捷径可寻? Oh: I'm using Linux, but my students will be using Windows, so I'm hoping for a cross-platform solution.
哦:我正在使用Linux,但是我的学生将使用Windows,所以我希望有一个跨平台的解决方案。
I am using tkinter
for displaying and PIL
for reading any image kind. 我正在使用
tkinter
进行显示,并使用PIL
来读取任何图像类型。 It is a veeerryyy slow solution. 这是一个很慢的解决方案。
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
The function pil2tkinter_image
takes a path to an image of any kind, png, bmp, jpg, gif and creates a tkinter PhotoImage out of it. 函数
pil2tkinter_image
可以获取任何类型的图像,png,bmp,jpg,gif的路径,并从中创建tkinter PhotoImage。
You can embed this Image in a tkinter Widget and use mouse events to read the pixel values. 您可以将该图像嵌入到tkinter窗口小部件中,并使用鼠标事件读取像素值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.