|
| 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 | +Overview |
| 8 | +-------- |
| 9 | + |
| 10 | +:class:`~pyqtgraph.ImageItem` displays images inside a |
| 11 | +:class:`~pyqtgraph.GraphicsView`, or a :class:`~pyqtgraph.ViewBox`, which may itself be |
| 12 | +part of a :class:`~pyqtgraph.PlotItem`. It is designed for rapid updates as needed for |
| 13 | +a video display. The supplied data is optionally scaled (see |
| 14 | +:meth:`ImageItem.setLevels <pyqtgraph.ImageItem.setLevels>`) and/or colored according |
| 15 | +to a lookup table (see :meth:`ImageItem.setColorMap <pyqtgraph.ImageItem.setColorMap>` |
| 16 | +and :meth:`ImageItem.setLookupTable <pyqtgraph.ImageItem.setLookupTable>`). |
10 | 17 |
|
11 | 18 | Data is provided as a NumPy array with an ordering of either |
12 | 19 |
|
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). |
| 20 | +* `col-major`, where the shape of the array represents (width, height) or |
| 21 | +* `row-major`, where the shape of the array represents (height, width). |
15 | 22 |
|
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. |
| 23 | +While `col-major` is the default, `row-major` ordering typically has the best |
| 24 | +performance. In either ordering, a third dimension can be added to the array to hold |
| 25 | +individual :python:`[R,G,B]` or :python:`[R,G,B,A]` channels/components. |
19 | 26 |
|
20 | 27 | Notes |
21 | 28 | ----- |
22 | 29 |
|
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 |
| 30 | +:class:`~pyqtgraph.ImageItem` is frequently used in conjunction with |
| 31 | +:class:`~pyqtgraph.ColorBarItem` to provide a color map display and interactive level |
| 32 | +adjustments, or with :class:`~pyqtgraph.HistogramLUTItem` or |
| 33 | +:class:`~pyqtgraph.HistogramLUTWidget` for a full GUI to control the levels and lookup |
| 34 | +table used to display the image. |
26 | 35 |
|
27 | 36 | 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. |
| 37 | +:meth:`ImageItem.setRect <pyqtgraph.ImageItem.setRect>` method or the `rect` keyword. |
| 38 | +This is internally realized through assigning a :class:`QTransform`. For other |
| 39 | +translation, scaling or rotations effects that persist for all later image data, the |
| 40 | +user can also directly define and assign such a transform, as shown in the example |
| 41 | +below. |
| 42 | + |
| 43 | +.. _ImageItem_performance: |
| 44 | + |
| 45 | +Performance |
| 46 | +----------- |
| 47 | + |
| 48 | +The performance of :class:`~pyqtgraph.ImageItem` can vary *significantly* based on |
| 49 | +attributes of the `image`, `levels` and `lut` input arguments. It should not be |
| 50 | +assumed that the default parameters are the most performant, as the default values are |
| 51 | +largely there to preserve backwards compatibility. |
| 52 | + |
| 53 | +The following guidance should be observed if performance is an important factor |
| 54 | + |
| 55 | +* Instantiate :class:`~pyqtgraph.ImageItem` with :python:`axisOrder='row-major'` |
| 56 | + |
| 57 | + * Alternatively, set the global configuration optionally |
| 58 | + :python:`pyqtgraph.setConfigOption('imageAxisOrder', 'row-major')` |
| 59 | + |
| 60 | +* Use C-contiguous image data. |
| 61 | +* For 1 or 3 channel data, use `uint8`, `uint16`, `float32`, or `float64` `image` |
| 62 | + dtype. |
| 63 | +* For 4-channel data, use `uint8` or `uint16` with :python:`levels=None`. |
| 64 | +* `levels` should be set to either to ``None`` or to single channel ``[min, max]`` |
| 65 | + |
| 66 | + * Not setting `levels` will trigger autoLevels sampling |
| 67 | + |
| 68 | +* If using LUTs (lookup tables), ensure they have a dtype of `uint8` and have 256 |
| 69 | + points or less. That can be accomplished with calling: |
| 70 | + |
| 71 | + * :func:`ImageItem.setColorMap <pyqtgraph.ImageItem.setColorMap>` or |
| 72 | + * :func:`ImageItem.setLookupTable <pyqtgraph.ImageItem.setLookupTable>` with |
| 73 | + :python:`ColorMap.getLookupTable(nPts=256)` (default is :python:`nPts=512`) |
| 74 | + |
| 75 | +* For floating point `image` arrays, prefer `float32` dtype to `float64` and avoid |
| 76 | + ``NaN`` values. |
| 77 | +* Enable Numba with :python:`pyqtgraph.setConfigOption('useNumba', True)` |
| 78 | + |
| 79 | + * JIT compilation will only accelerate repeated image display. |
| 80 | + |
| 81 | +Internally, pyqtgraph attempts to directly construct a :class:`QImage` using a |
| 82 | +combination of :class:`QImage.Format <QImage.Format>` options and |
| 83 | +:meth:`QImage.setColorTable <QImage.setColorTable>` if necessary. This does not work in |
| 84 | +all cases that pyqtgraph supports. If pyqtgraph is unable to construct the |
| 85 | +:class:`QImage` in such a fashion, it will fall back on |
| 86 | +:func:`~pyqtgraph.functions.makeARGB` to manipulate the data in a manner that |
| 87 | +:class:`QImage` can read it in. There is a *significant* performance penalty when |
| 88 | +having to use :func:`~pyqtgraph.functions.makeARGB`. |
| 89 | + |
| 90 | +For applications that are *very* performance sensitive, every effort should be made so |
| 91 | +that the arguments passed to :meth:`ImageItem.setImage <pyqtgraph.ImageItem.setImage>` |
| 92 | +do not call :func:`~pyqtgraph.functions.makeARGB`. |
47 | 93 |
|
48 | 94 | .. _ImageItem_examples: |
49 | 95 |
|
50 | 96 | Examples |
51 | 97 | -------- |
52 | 98 |
|
| 99 | +Scale and Position ImageItem |
| 100 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 101 | + |
| 102 | +In the following example, it is demonstrated how a user scale and translate a |
| 103 | +:class:`~pyqtgraph.ImageItem` within a :class:`~pyqtgraph.ViewBox` to occupy a specific |
| 104 | +position and size. |
| 105 | + |
53 | 106 | .. literalinclude:: /images/gen_example_imageitem_transform.py |
54 | | - :lines: 19-28 |
55 | | - :dedent: 8 |
| 107 | + :lines: 4-44 |
| 108 | + :emphasize-lines: 24-33 |
| 109 | + :language: python |
56 | 110 |
|
57 | 111 | .. thumbnail:: |
58 | 112 | /images/example_imageitem_transform.png |
59 | 113 | :width: 49% |
60 | 114 | :alt: Example of transformed image display |
61 | 115 | :title: Transformed Image Display |
62 | 116 |
|
| 117 | +Inheritance |
| 118 | +----------- |
| 119 | + |
| 120 | +.. inheritance-diagram:: pyqtgraph.graphicsItems.ImageItem.ImageItem |
| 121 | + :top-classes: PyQt6.QtCore.QObject, PyQt6.QtWidgets.QGraphicsItem |
| 122 | + :parts: 1 |
| 123 | + |
| 124 | +API |
| 125 | +--- |
63 | 126 |
|
64 | 127 | .. autoclass:: pyqtgraph.ImageItem |
65 | 128 | :members: |
66 | | - |
67 | | - .. automethod:: pyqtgraph.ImageItem.__init__ |
|
0 commit comments