mirror of
https://github.com/wassname/scikit-image.git
synced 2026-10-02 12:41:06 +08:00
Add QT4 image display plugin.
This commit is contained in:
1 parent
3f9678caf7
commit
2eb28f4e85
2 files changed
+32
No files matched your search
@@ -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