2010-03-22 05:48:52 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-20 16:13:50 +00:00
|
|
|
"""
|
2021-02-26 00:14:34 +00:00
|
|
|
This example demonstrates the use of ImageView with 3-color image stacks.
|
|
|
|
ImageView is a high-level widget for displaying and analyzing 2D and 3D data.
|
|
|
|
ImageView provides:
|
2013-02-20 16:13:50 +00:00
|
|
|
|
|
|
|
1. A zoomable region (ViewBox) for displaying the image
|
|
|
|
2. A combination histogram and gradient editor (HistogramLUTItem) for
|
|
|
|
controlling the visual appearance of the image
|
|
|
|
3. A timeline for selecting the currently displayed frame (for 3D data only).
|
|
|
|
4. Tools for very basic analysis of image data (see ROI and Norm buttons)
|
|
|
|
|
|
|
|
"""
|
2010-03-22 06:21:56 +00:00
|
|
|
## Add path to library (just for examples; you do not need this)
|
2012-12-26 22:51:52 +00:00
|
|
|
import initExample
|
2011-04-05 14:35:50 +00:00
|
|
|
|
|
|
|
import numpy as np
|
2012-03-02 03:58:02 +00:00
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
2011-04-05 14:35:50 +00:00
|
|
|
import pyqtgraph as pg
|
2010-03-22 05:48:52 +00:00
|
|
|
|
2016-08-31 22:14:25 +00:00
|
|
|
# Interpret image data as row-major instead of col-major
|
|
|
|
pg.setConfigOptions(imageAxisOrder='row-major')
|
2016-04-28 05:33:51 +00:00
|
|
|
|
2021-01-27 18:59:07 +00:00
|
|
|
app = pg.mkQApp("ImageView Example")
|
2010-03-22 06:21:56 +00:00
|
|
|
|
|
|
|
## Create window with ImageView widget
|
2010-03-22 05:48:52 +00:00
|
|
|
win = QtGui.QMainWindow()
|
2011-06-14 23:47:52 +00:00
|
|
|
win.resize(800,800)
|
2011-04-05 14:35:50 +00:00
|
|
|
imv = pg.ImageView()
|
2010-03-22 05:48:52 +00:00
|
|
|
win.setCentralWidget(imv)
|
|
|
|
win.show()
|
2013-02-25 04:09:03 +00:00
|
|
|
win.setWindowTitle('pyqtgraph example: ImageView')
|
2010-03-22 05:48:52 +00:00
|
|
|
|
2021-02-26 00:14:34 +00:00
|
|
|
## Create random 3D data set with time varying signals
|
|
|
|
dataRed = np.ones((100, 200, 200)) * np.linspace(90, 150, 100)[:, np.newaxis, np.newaxis]
|
|
|
|
dataRed += pg.gaussianFilter(np.random.normal(size=(200, 200)), (5, 5)) * 100
|
|
|
|
dataGrn = np.ones((100, 200, 200)) * np.linspace(90, 180, 100)[:, np.newaxis, np.newaxis]
|
|
|
|
dataGrn += pg.gaussianFilter(np.random.normal(size=(200, 200)), (5, 5)) * 100
|
|
|
|
dataBlu = np.ones((100, 200, 200)) * np.linspace(180, 90, 100)[:, np.newaxis, np.newaxis]
|
|
|
|
dataBlu += pg.gaussianFilter(np.random.normal(size=(200, 200)), (5, 5)) * 100
|
2010-07-24 18:29:09 +00:00
|
|
|
|
2021-02-26 00:14:34 +00:00
|
|
|
data = np.concatenate(
|
|
|
|
(dataRed[:, :, :, np.newaxis], dataGrn[:, :, :, np.newaxis], dataBlu[:, :, :, np.newaxis]), axis=3
|
|
|
|
)
|
2010-07-24 18:29:09 +00:00
|
|
|
|
2010-03-22 06:21:56 +00:00
|
|
|
|
2013-02-20 16:13:50 +00:00
|
|
|
## Display the data and assign each frame a time value from 1.0 to 3.0
|
2011-04-05 14:35:50 +00:00
|
|
|
imv.setImage(data, xvals=np.linspace(1., 3., data.shape[0]))
|
2010-03-22 06:21:56 +00:00
|
|
|
|
2016-02-15 21:58:57 +00:00
|
|
|
## Set a custom color map
|
2016-04-03 06:27:20 +00:00
|
|
|
colors = [
|
|
|
|
(0, 0, 0),
|
|
|
|
(45, 5, 61),
|
|
|
|
(84, 42, 55),
|
|
|
|
(150, 87, 60),
|
|
|
|
(208, 171, 141),
|
|
|
|
(255, 255, 255)
|
|
|
|
]
|
|
|
|
cmap = pg.ColorMap(pos=np.linspace(0.0, 1.0, 6), color=colors)
|
|
|
|
imv.setColorMap(cmap)
|
2016-02-15 21:58:57 +00:00
|
|
|
|
2021-02-26 00:14:34 +00:00
|
|
|
# Start up with an ROI
|
|
|
|
imv.ui.roiBtn.setChecked(True)
|
|
|
|
imv.roiClicked()
|
|
|
|
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
2021-05-13 21:28:22 +00:00
|
|
|
pg.exec()
|