1
1
import os
2
+ import pathlib
2
3
import warnings
3
4
from collections .abc import Callable
4
5
21
22
22
23
23
24
class ImageItem (GraphicsObject ):
24
- """
25
+ """Graphics object used to display image data.
26
+
27
+ ImageItem can render images with 1, 3 or 4 channels, use lookup tables to apply
28
+ false colors to images, and users can either set levels limits, or rely on
29
+ the auto-sampling.
30
+
31
+ Performance can vary wildly based on the attributes of the inputs provided, see
32
+ :ref:`performance <ImageItem_performance>` for guidance if performance is an
33
+ important factor.
34
+
35
+ There is optional `numba` and `cupy` support.
36
+
25
37
**Bases:** :class:`pyqtgraph.GraphicsObject`
26
38
27
39
Signals
@@ -93,23 +105,24 @@ def setCompositionMode(self, mode: QtGui.QPainter.CompositionMode):
93
105
Composition of the item, often used when overlaying items. Common
94
106
options include:
95
107
96
- * `` QPainter.CompositionMode.CompositionMode_SourceOver` `
108
+ * `QPainter.CompositionMode.CompositionMode_SourceOver`
97
109
Image replaces the background if it is opaque. Otherwise, it uses the
98
110
alpha channel to blend the image with the background, default
99
- * `` QPainter.CompositionMode.CompositionMode_Overlay` ` Image color is
111
+ * `QPainter.CompositionMode.CompositionMode_Overlay` Image color is
100
112
mixed with the background color to reflect the lightness or darkness of
101
113
the background
102
- * `` QPainter.CompositionMode.CompositionMode_Plus` ` Both the alpha and
114
+ * `QPainter.CompositionMode.CompositionMode_Plus` Both the alpha and
103
115
color of the image and background pixels are added together.
104
- * `` QPainter.CompositionMode.CompositionMode_Plus` ` The output is the
116
+ * `QPainter.CompositionMode.CompositionMode_Plus` The output is the
105
117
image color multiplied by the background.
106
118
107
119
See :class:`QPainter.CompositionMode <QPainter.CompositionMode>` in the Qt
108
120
documentation for more options and details
109
121
110
122
See Also
111
123
--------
112
- :class:`QPainter.CompositionMode <QPainter.CompositionMode>`
124
+ :class:`QPainter.CompositionMode <QPainter.CompositionMode>` : Details all the
125
+ possible composition mode options accepted.
113
126
"""
114
127
self .paintMode = mode
115
128
self .update ()
@@ -181,7 +194,7 @@ def setLevels(self, levels: npt.ArrayLike | None, update: bool=True):
181
194
def getLevels (self ) -> numpy .ndarray | None :
182
195
"""
183
196
Returns the array representing the current level settings. See
184
- :func:`setLevels`. When `` autoLevels` ` is active, the format is
197
+ :func:`setLevels`. When `autoLevels` is active, the format is
185
198
``[blackLevel, whiteLevel]``.
186
199
"""
187
200
return self .levels
@@ -199,8 +212,7 @@ def setColorMap(self, colorMap: colormap.ColorMap | str):
199
212
Raises
200
213
------
201
214
TypeError
202
- Raised when ``colorMap`` is not of type ``str`` or
203
- :class:`~pyqtgraph.ColorMap`
215
+ Raised when `colorMap` is not of type `str` or :class:`~pyqtgraph.ColorMap`
204
216
"""
205
217
if isinstance (colorMap , colormap .ColorMap ):
206
218
self ._colorMap = colorMap
@@ -220,7 +232,7 @@ def getColorMap(self) -> colormap.ColorMap | None:
220
232
return self ._colorMap
221
233
222
234
def setLookupTable (self , lut : npt .ArrayLike | Callable , update : bool = True ):
223
- """Sets lookup table `` lut` ` to use for false color display of a monochrome
235
+ """Sets lookup table `lut` to use for false color display of a monochrome
224
236
image. See :func:`makeARGB <pyqtgraph.functions.makeARGB>` for more
225
237
information on how this is used.
226
238
@@ -230,7 +242,7 @@ def setLookupTable(self, lut: npt.ArrayLike | Callable, update: bool=True):
230
242
Parameters
231
243
----------
232
244
lut : array_like or callable
233
- `` lut` ` can be a callable that accepts the current image as an argument and
245
+ `lut` can be a callable that accepts the current image as an argument and
234
246
returns the lookup table to use.
235
247
update : bool, optional
236
248
Update the intermediate image, by default True.
@@ -269,9 +281,9 @@ def setAutoDownsample(self, active: bool=True):
269
281
active : bool, optional
270
282
If `active` is `True`, the image is automatically downsampled to match the
271
283
screen resolution. This improves performance for large images and reduces
272
- aliasing. If `` autoDownsample` ` is not specified, then ImageItem will
284
+ aliasing. If `autoDownsample` is not specified, then ImageItem will
273
285
choose whether to downsample the image based on its size. ``False``
274
- disables automatic downsampling. by default True
286
+ disables automatic downsampling. by default `` True``
275
287
"""
276
288
self .autoDownsample = active
277
289
self ._renderRequired = True
@@ -355,7 +367,7 @@ def setOpts(self, update: bool=True, **kargs):
355
367
356
368
def setRect (self , * args ):
357
369
"""Sets translation and scaling of this ImageItem to display the current image
358
- within the rectangle given as `` rect` ` (:class:`QRect` or :class:`QRectF`), or
370
+ within the rectangle given as `rect` (:class:`QRect` or :class:`QRectF`), or
359
371
described by parameters `x, y, w, h`, defining starting position, width and
360
372
height.
361
373
@@ -372,7 +384,7 @@ def setRect(self, *args):
372
384
373
385
See Also
374
386
--------
375
- :class:`QRectF`
387
+ :class:`QRectF` : See constructor methods for allowable ``*args``
376
388
"""
377
389
if not args :
378
390
# reset scaling and rotation when called without argument
@@ -439,8 +451,8 @@ def setImage(
439
451
search subsamples the images and may miss individual bright or dark points
440
452
in the data set. If `False`, the search will be omitted.
441
453
442
- The default is `False` if a `` levels` ` keyword argument is given, and
443
- `True` otherwise.
454
+ The default is `` False`` if a `levels` keyword argument is given, and
455
+ `` True` ` otherwise.
444
456
levelSamples : int, default 65536
445
457
When determining minimum and maximum values, ImageItem only inspects a
446
458
subset of pixels no larger than this number. Setting this larger than the
@@ -457,7 +469,7 @@ def setImage(
457
469
imageitem.setImage(imagedata.T)
458
470
459
471
or the interpretation of the data can be changed locally through the
460
- `` axisOrder` ` keyword or by changing the `imageAxisOrder`
472
+ `axisOrder` keyword or by changing the `imageAxisOrder`
461
473
:ref:`global configuration option <apiref_config>`
462
474
463
475
For more information on how the image is processed before displaying, see
@@ -740,20 +752,20 @@ def paint(self, p, *args):
740
752
p .setPen (self .border )
741
753
p .drawRect (self .boundingRect ())
742
754
743
- def save (self , fileName : str , * args ):
755
+ def save (self , fileName : str | pathlib . Path , * args ):
744
756
"""Saves this image to file. Note that this saves the visible image
745
757
(after scale/color changes), not the original data.
746
758
747
759
Parameters
748
760
----------
749
- fileName : str
761
+ fileName : str or pathlib.Path
750
762
path to save the image to
751
763
*args : tuple
752
764
arguments that are passed to :meth:`QImage.save <QImage.save>`
753
765
754
766
See Also
755
767
--------
756
- :meth:`QImage.save <QImage.save>`
768
+ :meth:`QImage.save <QImage.save>` : ``*args`` is relayed to this method
757
769
"""
758
770
759
771
if self ._renderRequired :
@@ -775,15 +787,15 @@ def getHistogram(
775
787
Parameters
776
788
----------
777
789
bins : int or str, optional
778
- The `` bins` ` argument and any extra keyword arguments are passed to
790
+ The `bins` argument and any extra keyword arguments are passed to
779
791
:func:`numpy.histogram()`. If ``bins == 'auto'``, a bin number is
780
792
automatically chosen based on the image characteristics, by default
781
- `` 'auto'` `
793
+ `'auto'`
782
794
step : str or int, optional
783
- The `` step` ` argument causes pixels to be skipped when computing the
795
+ The `step` argument causes pixels to be skipped when computing the
784
796
histogram to save time. If `step` is 'auto', then a step is chosen such
785
797
that the analyzed data has dimensions approximating `targetImageSize`
786
- for each axis, by default `` 'auto'` `
798
+ for each axis, by default `'auto'`
787
799
perChannel : bool, optional
788
800
If ``True``, then a histogram is computed for each channel,
789
801
and the output is a list of the results, by default ``False``
@@ -803,7 +815,7 @@ def getHistogram(
803
815
804
816
See Also
805
817
--------
806
- numpy.histogram
818
+ numpy.histogram : describes return format in greater detail
807
819
"""
808
820
809
821
if 'targetHistogramSize' in kwds :
@@ -873,12 +885,15 @@ def setPxMode(self, b: bool):
873
885
If ``True``, the item will not inherit any scale or rotation transformations from its
874
886
parent items, but its position will be transformed as usual.
875
887
876
- Read the description of ``ItemIgnoresTransformations`` member of the
877
- :class:`QGraphicsItem.GraphicsItemFlag` enum in the Qt documentation
888
+ Parameters
889
+ ----------
890
+ b : bool
891
+ Enable pixel model, thus ignoring transformations
878
892
879
893
See Also
880
894
--------
881
- :class:`QGraphicsItem.GraphicsItemFlag`
895
+ :class:`QGraphicsItem.GraphicsItemFlag` : Read the description of
896
+ `ItemIgnoresTransformations` for more information
882
897
883
898
"""
884
899
self .setFlag (
@@ -976,7 +991,7 @@ def hoverEvent(self, ev):
976
991
if self .drawKernel is not None and ev .acceptDrags (
977
992
QtCore .Qt .MouseButton .LeftButton
978
993
):
979
- # we don't use the click, but we also don't want anyone else to use it
994
+ # we don't use the click, but we also don't want anyone else to use it
980
995
ev .acceptClicks (QtCore .Qt .MouseButton .LeftButton )
981
996
ev .acceptClicks (QtCore .Qt .MouseButton .RightButton )
982
997
elif self .removable :
0 commit comments