ImageItem — pyqtgraph 0.9.8 documentation

### Navigation

- index
- modules |
- next |
- previous |
- pyqtgraph 0.9.8 documentation »
- API Reference »
- Pyqtgraph’s Graphics Items »

# ImageItem

class `pyqtgraph.` `ImageItem`(image=None, **kargs)

  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)

    See `setImage` for all allowed initialization arguments.

  `getHistogram`(bins=500, step=3)

    Returns x and y arrays containing the histogram values for the current image. The step argument causes pixels to be skipped when computing the histogram to save time. This method is also used when automatically computing levels.

  `pixelSize`()

    return scene-size of a single pixel in the image

  `save`(fileName, *args)

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

  `setCompositionMode`(mode)

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

    Most common arguments: |
    QtGui.QPainter.CompositionMode_SourceOver | Default; image replaces the background if it is opaque. Otherwise, it uses the alpha channel to blend the image with the background.
    QtGui.QPainter.CompositionMode_Overlay | The image color is mixed with the background color to reflect the lightness or darkness of the background.
    QtGui.QPainter.CompositionMode_Plus | Both the alpha and color of the image and background pixels are added together.
    QtGui.QPainter.CompositionMode_Multiply | The output is the image color multiplied by the background.

  `setImage`(image=None, autoLevels=None, **kargs)

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

    Arguments: |
    image | (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).
    autoLevels | (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.
    lut | (numpy array) The color lookup table to use when displaying the image. See `setLookupTable`.
    levels | (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.
    opacity | (float 0.0-1.0)
    compositionMode | see `setCompositionMode`
    border | Sets the pen used when drawing the image border. Default is None.

  `setLevels`(levels, update=True)

    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)

    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`.

  `setPxMode`(b)

    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)

  `setRect`(rect)

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

### Navigation

- index
- modules |
- next |
- previous |
- pyqtgraph 0.9.8 documentation »
- API Reference »
- Pyqtgraph’s Graphics Items »