class pyqtgraph.ImageItem(image=None, **kargs)[source]

Bases: GraphicsObject

GraphicsObject displaying an image. Optimized for rapid update (ie video display). This item displays either a 2D numpy array (height, width) or a 3D array (height, width, RGBa). This array is optionally scaled (see setLevels) and/or colored with a lookup table (see setLookupTable) before being displayed.

ImageItem is frequently used in conjunction with HistogramLUTItem or HistogramLUTWidget to provide a GUI for controlling the levels and lookup table used to display the image.

__init__(image=None, **kargs)[source]

See setImage for all allowed initialization arguments.


Return the transform that maps from this image’s input array to its local coordinate system.

This transform corrects for the transposition that occurs when image data is interpreted in row-major order.

getHistogram(bins='auto', step='auto', perChannel=False, targetImageSize=200, targetHistogramSize=500, **kwds)[source]

Returns x and y arrays containing the histogram values for the current image. For an explanation of the return format, see numpy.histogram().

The step argument causes pixels to be skipped when computing the histogram to save time. If step is ‘auto’, then a step is chosen such that the analyzed data has dimensions roughly targetImageSize for each axis.

The bins argument and any extra keyword arguments are passed to self.xp.histogram(). If bins is ‘auto’, then a bin number is automatically chosen based on the image characteristics:

  • Integer images will have approximately targetHistogramSize bins, with each bin having an integer width.

  • All other types will have targetHistogramSize bins.

If perChannel is True, then the histogram is computed once per channel and the output is a list of the results.

This method is also used when automatically computing levels.


Return the transform that maps from this image’s local coordinate system to its input array.

See dataTransform() for more information.


return scene-size of a single pixel in the image


Estimate the min/max values of the image data by subsampling.

save(fileName, *args)[source]

Save this image to file. Note that this saves the visible image (after scale/color changes), not the original data.


Set the automatic downsampling mode for this ImageItem.

Added in version 0.9.9


Change the composition mode of the item (see QPainter::CompositionMode in the Qt documentation). This is useful when overlaying multiple ImageItems.

Most common arguments:


Default; image replaces the background if it is opaque. Otherwise, it uses the alpha channel to blend the image with the background.


The image color is mixed with the background color to reflect the lightness or darkness of the background.


Both the alpha and color of the image and background pixels are added together.


The output is the image color multiplied by the background.

setImage(image=None, autoLevels=None, **kargs)[source]

Update the image displayed by this item. For more information on how the image is processed before displaying, see makeARGB



(numpy array) Specifies the image data. May be 2D (width, height) or 3D (width, height, RGBa). The array dtype must be integer or floating point of any bit depth. For 3D arrays, the third dimension must be of length 3 (RGB) or 4 (RGBA). See notes below.


(bool) If True, this forces the image to automatically select levels based on the maximum and minimum values in the data. By default, this argument is true unless the levels argument is given.


(numpy array) The color lookup table to use when displaying the image. See setLookupTable.


(min, max) The minimum and maximum values to use when rescaling the image data. By default, this will be set to the minimum and maximum values in the image. If the image array has dtype uint8, no rescaling is necessary.


(float 0.0-1.0)


See setCompositionMode


Sets the pen used when drawing the image border. Default is None.


(bool) If True, the image is automatically downsampled to match the screen resolution. This improves performance for large images and reduces aliasing. If autoDownsample is not specified, then ImageItem will choose whether to downsample the image based on its size.


For backward compatibility, image data is assumed to be in column-major order (column, row). However, most image data is stored in row-major order (row, column) and will need to be transposed before calling setImage():


This requirement can be changed by calling image.setOpts(axisOrder='row-major') or by changing the imageAxisOrder global configuration option.

setLevels(levels, update=True)[source]

Set image scaling levels. Can be one of:

  • [blackLevel, whiteLevel]

  • [[minRed, maxRed], [minGreen, maxGreen], [minBlue, maxBlue]]

Only the first format is compatible with lookup tables. See makeARGB for more details on how levels are applied.

setLookupTable(lut, update=True)[source]

Set the lookup table (numpy array) to use for this image. (see makeARGB for more information on how this is used). Optionally, lut can be a callable that accepts the current image as an argument and returns the lookup table to use.

Ordinarily, this table is supplied by a HistogramLUTItem or GradientEditorItem.


Set whether the item ignores transformations and draws directly to screen pixels. If True, the item will not inherit any scale or rotation transformations from its parent items, but its position will be transformed as usual. (see GraphicsItem::ItemIgnoresTransformations in the Qt documentation)


Scale and translate the image to fit within rect (must be a QRect or QRectF).