问题描述
我正在与作为第二个monbitor连接的空间光调制器(SLM)一起工作. SLM具有tzo接收式8位灰度图像.我目前正在与vispy一起在SLM上显示图像,但是如果正确显示了这些图像,我不会支持.可以使用vispy灰度显示图像吗?我使用此代码显示图像
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
感谢您的帮助,对不起英语不好
您可以将图片从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()
i'm working with a spatial light modulator (SLM) which is connected as a second monbitor. The SLM has tzo recive 8-bit grayscale images.I am currently working with vispy to display the images on the SLM, but i'm not shore if they are diplayed correctly. Is there any possibility to display an image on grayscale using vispy?
I disply the images using this code
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()
from http://vispy.readthedocs.io/en/stable/examples/basics/scene/image.html
thanks for your help, and sorry for bad english
You can transform your picture from RGB to gray (see this post) and then use the 'grays' colormap.
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()
这篇关于使用vispy以灰度显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!