mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-29 00:23:43 +08:00
Add QT4 image display plugin.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import pil_plugin
|
||||
import matplotlib_plugin
|
||||
import qt_plugin
|
||||
|
||||
from plugin import register as register_plugin
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user