mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-13 05:17:07 +08:00
32 lines
679 B
Python
32 lines
679 B
Python
import plugin
|
|
import numpy as np
|
|
|
|
try:
|
|
from PyQt4.QtGui import QApplication, QImage, QPixmap, QLabel
|
|
except ImportError:
|
|
have_qt = False
|
|
else:
|
|
have_qt = True
|
|
|
|
def show(arr):
|
|
arr = np.ascontiguousarray(arr.astype(np.uint8))
|
|
if arr.ndim != 3:
|
|
raise ValueError("Qt only displays colour images.")
|
|
|
|
if arr.shape[-1] == 4:
|
|
raise ValueError("Alpha channels not yet supported.")
|
|
|
|
img = QImage(arr.data, arr.shape[1], arr.shape[0], QImage.Format_RGB888)
|
|
pm = QPixmap.fromImage(img)
|
|
|
|
app = QApplication([])
|
|
|
|
label = QLabel()
|
|
label.setPixmap(pm)
|
|
label.show()
|
|
|
|
app.exec_()
|
|
|
|
if have_qt:
|
|
plugin.register('qt', show=show)
|