1
+ .. role :: python(code)
2
+ :language: python
3
+
1
4
ImageItem
2
5
=========
3
6
4
- :class: `~pyqtgraph.ImageItem ` displays images inside a :class: `~pyqtgraph.GraphicsView `, or a
5
- :class: `~pyqtgraph.ViewBox `, which may itself be part of a :class: `~pyqtgraph.PlotItem `. It is designed
6
- for rapid updates as needed for a video display. The supplied data is optionally scaled (see
7
- :func: `~pyqtgraph.ImageItem.setLevels `) and/or colored according to a
8
- lookup table (see :func: `~pyqtgraph.ImageItem.setColorMap ` and
9
- :func: `~pyqtgraph.ImageItem.setLookupTable `).
7
+ :class: `~pyqtgraph.ImageItem ` displays images inside a
8
+ :class: `~pyqtgraph.GraphicsView `, or a :class: `~pyqtgraph.ViewBox `, which may itself be
9
+ part of a :class: `~pyqtgraph.PlotItem `. It is designed for rapid updates as needed for
10
+ a video display. The supplied data is optionally scaled (see
11
+ :meth: `ImageItem.setLevels <pyqtgraph.ImageItem.setLevels> `) and/or colored according
12
+ to a lookup table (see :meth: `ImageItem.setColorMap <pyqtgraph.ImageItem.setColorMap> `
13
+ and :meth: `ImageItem.setLookupTable <pyqtgraph.ImageItem.setLookupTable> `).
10
14
11
15
Data is provided as a NumPy array with an ordering of either
12
16
13
- * `col-major `, where the shape of the array represents (width, height) or
14
- * `row-major `, where the shape of the array represents (height, width).
17
+ * `col-major `, where the shape of the array represents (width, height) or
18
+ * `row-major `, where the shape of the array represents (height, width).
15
19
16
- While `col-major ` is the default, `row-major ` ordering typically has the best performance. In either ordering,
17
- a third dimension can be added to the array to hold individual
18
- `` [R,G,B] `` or `` [R,G,B,A] `` components.
20
+ While `col-major ` is the default, `row-major ` ordering typically has the best
21
+ performance. In either ordering, a third dimension can be added to the array to hold
22
+ individual :python: ` [R,G,B] ` or :python: ` [R,G,B,A] ` channels/ components.
19
23
20
24
Notes
21
25
-----
22
26
23
- Data ordering can be set for each ImageItem, or in the :ref: `global configuration options <apiref_config >` by ::
24
-
25
- pyqtgraph.setConfigOption('imageAxisOrder', 'row-major') # best performance
26
-
27
27
An image can be placed into a plot area of a given extent directly through the
28
- :func: `~pyqtgraph.ImageItem.setRect ` method or the ``rect `` keyword. This is internally realized through
29
- assigning a ``QtGui.QTransform ``. For other translation, scaling or rotations effects that
30
- persist for all later image data, the user can also directly define and assign such a
31
- transform, as shown in the example below.
32
-
33
- ImageItem is frequently used in conjunction with :class: `~pyqtgraph.ColorBarItem ` to provide
34
- a color map display and interactive level adjustments, or with
35
- :class: `~pyqtgraph.HistogramLUTItem ` or :class: `~pyqtgraph.HistogramLUTWidget ` for a full GUI
36
- to control the levels and lookup table used to display the image.
37
-
38
- If performance is critial, the following points may be worth investigating:
39
-
40
- * Use row-major ordering and C-contiguous image data.
41
- * Manually provide ``level `` information to avoid autoLevels sampling of the image.
42
- * Prefer `float32 ` to `float64 ` for floating point data, avoid NaN values.
43
- * Use lookup tables with <= 256 entries for false color images.
44
- * Avoid individual level adjustments RGB components.
45
- * Use the latest version of NumPy. Notably, SIMD code added in version 1.20 significantly improved performance on Linux platforms.
46
- * Enable Numba with ``pyqtgraph.setConfigOption('useNumba', True) ``, although the JIT compilation will only accelerate repeated image display.
28
+ :meth: `ImageItem.setRect <pyqtgraph.ImageItem.setRect> ` method or the ``rect `` keyword.
29
+ This is internally realized through assigning a :class: `QTransform `. For other
30
+ translation, scaling or rotations effects that persist for all later image data, the
31
+ user can also directly define and assign such a transform, as shown in the example
32
+ below.
33
+
34
+ :class: `~pyqtgraph.ImageItem ` is frequently used in conjunction with
35
+ :class: `~pyqtgraph.ColorBarItem ` to provide a color map display and interactive level
36
+ adjustments, or with :class: `~pyqtgraph.HistogramLUTItem ` or
37
+ :class: `~pyqtgraph.HistogramLUTWidget ` for a full GUI to control the levels and lookup
38
+ table used to display the image.
39
+
40
+ Performance
41
+ -----------
42
+
43
+ The performance of :class: `~pyqtgraph.ImageItem ` can vary *significantly * based on
44
+ attributes of the ``image ``, ``levels `` and ``lut `` input arguments. It should not be
45
+ assumed that the default parameters are the most performant, as the default values are
46
+ largely there to preserve backwards compatibility.
47
+
48
+ The following guidance should be observed if performance is an important factor
49
+
50
+ * Instantiate :class: `~pyqtgraph.ImageItem ` with :python: `axisOrder='row-major' `
51
+
52
+ * Alternatively, set the global configuration optionally
53
+ :python: `pyqtgraph.setConfigOption('imageAxisOrder', 'row-major') `
54
+
55
+ * Use C-contiguous image data.
56
+ * For 1 or 3 channel data, use `uint8 `, `uint16 `, `float32 `, or `float64 `
57
+ ``image `` dtype.
58
+ * For 4-channel data, use `uint8 ` or `uint16 ` with :python":`levels=None `.
59
+ * ``levels `` should be single channel (if 1 or 3 channel data).
60
+
61
+ * Setting :python: `levels=None ` will trigger autoLevels sampling, and thus should
62
+ be avoided if possible.
63
+
64
+ * If using LUTs (lookup tables), ensure they have a dtype of `uint8 ` and have 256
65
+ points or less, and that. That can be accomplished with calling:
66
+
67
+ * :func: `ImageItem.setColorMap <pyqtgraph.ImageItem.setColorMap> ` or
68
+ * :func: `ImageItem.setLookupTable <pyqtgraph.ImageItem.setLookupTable> ` with
69
+ :python: `ColorMap.getLookupTable(nPts=256) ` (default is :python: `nPts=512 `)
70
+
71
+ * For floating point ``image `` arrays, prefer `float32 ` dtype to `float64 `
72
+ and avoid ``NaN `` values.
73
+ * Enable Numba with :python: `pyqtgraph.setConfigOption('useNumba', True) `
74
+
75
+ * JIT compilation will only accelerate repeated image display.
76
+
77
+ Internally, pyqtgraph attempts to directly construct a :class: `QImage ` using a
78
+ combination of :class: `QImage.Format <QImage.Format> ` options and
79
+ :meth: `QImage.setColorTable <QImage.setColorTable> ` if necessary. This does not work in
80
+ all cases that pyqtgraph supports. If pyqtgraph is unable to construct the
81
+ :class: `QImage ` in such a fashion, it will fall back on
82
+ :func: `~pyqtgraph.functions.makeARGB ` to manipulate the data in a manner that
83
+ :class: `QImage ` can read it in. There is a *significant * performance penalty when
84
+ having to use :func: `~pyqtgraph.functions.makeARGB `.
85
+
86
+ For applications that are *very * performance sensitive, every effort should be made so
87
+ that the arguments passed to :meth: `ImageItem.setImage <pyqtgraph.ImageItem.setImage> `
88
+ do not call :func: `~pyqtgraph.functions.makeARGB `.
47
89
48
90
.. _ImageItem_examples :
49
91
@@ -53,13 +95,16 @@ Examples
53
95
.. literalinclude :: /images/gen_example_imageitem_transform.py
54
96
:lines: 19-28
55
97
:dedent: 8
98
+ :language: python
56
99
57
100
.. thumbnail ::
58
101
/images/example_imageitem_transform.png
59
102
:width: 49%
60
103
:alt: Example of transformed image display
61
104
:title: Transformed Image Display
62
105
106
+ API
107
+ ---
63
108
64
109
.. autoclass :: pyqtgraph.ImageItem
65
110
:members:
0 commit comments