gpt4 book ai didi

python - 使用 vispy 以灰度显示图像

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:43 26 4
gpt4 key购买 nike

我正在使用空间光调制器(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 转换为灰色(请参阅 this post ),然后使用“灰色”颜色图。

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()

关于python - 使用 vispy 以灰度显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39826807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com