2016-10-03 59 views
0

我正在使用作爲第二個monobitor連接的空間光調製器(SLM)。 SLM有tzo recive 8位灰度圖像。 我目前正在使用vispy在SLM上顯示圖像,但如果它們正確顯示,我不會支持。 有沒有可能使用vispy在灰度顯示圖像?使用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

感謝您的幫助,並抱歉不好英語

回答

0

您可以從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() 
+0

它的工作原理!謝謝! – stanissse