使用vispy灰度显示图像(Display image in Grayscale using vis

2019-09-26 15:16发布

我正在与其连接作为第二monbitor一个空间光调制器(SLM)的工作。 该SLM具有TZO recive 8位灰度图像。 我目前正在与vispy合作,显示在SLM的图像,但如果是正确diplayed我不是托。 是否有可能使用vispy上显示灰阶图像?

我DISPLY使用此代码的图像

import sys
from vispy import scene
from vispy import app
import numpy as np

canvas = scene.SceneCanvas(keys='interactive')
canvas.size = 800, 600
canvas.show()

# Set up a viewbox to display the image with interactive pan/zoom
view = canvas.central_widget.add_view()

# Create the image
img_data = *my image*
image = scene.visuals.Image(img_data, parent=view.scene)

# Set 2D camera (the camera will scale to the contents in the scene)
view.camera = scene.PanZoomCamera(aspect=1)

if __name__ == '__main__' and sys.flags.interactive == 0:
    app.run()

从http://vispy.readthedocs.io/en/stable/examples/basics/scene/image.html

感谢您的帮助,而对于英语不好对不起

Answer 1:

您可以从RGB转换你的图片为灰色(见这篇文章 ),然后使用“灰”颜色表。

import sys
from vispy import scene
from vispy import app
import numpy as np
from vispy.io import load_data_file, read_png

canvas = scene.SceneCanvas(keys='interactive')
canvas.size = 800, 600
canvas.show()

# Set up a viewbox to display the image with interactive pan/zoom
view = canvas.central_widget.add_view()

# Define a function to tranform a picture to gray
def rgb2gray(rgb):
    return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])

# Load the image
img_data = read_png(load_data_file('mona_lisa/mona_lisa_sm.png'))

# Apply transformation
img_data = rgb2gray(img_data)

# Image visual
image = scene.visuals.Image(img_data, cmap='grays', parent=view.scene)

# Set 2D camera (the camera will scale to the contents in the scene)
view.camera = scene.PanZoomCamera(aspect=1)
view.camera.set_range()
view.camera.flip = (0, 1, 0)

if __name__ == '__main__' and sys.flags.interactive == 0:
    app.run()


文章来源: Display image in Grayscale using vispy
标签: python vispy