ImageView#

class pyqtgraph.ImageView(
parent=None,
name='ImageView',
view=None,
imageItem=None,
levelMode='mono',
discreteTimeLine=False,
roi=None,
normRoi=None,
*args,
)[source]#

Widget used for display and analysis of image data. Implements many features:

  • Displays 2D and 3D image data. For 3D data, a z-axis slider is displayed allowing the user to select which frame is displayed.

  • Displays histogram of image data with movable region defining the dark/light levels

  • Editable gradient provides a color lookup table

  • Frame slider may also be moved using left/right arrow keys as well as pgup, pgdn, home, and end.

  • Basic analysis features including:

    • ROI and embedded plot for measuring image values across frames

    • Image normalization / background subtraction

Basic Usage:

imv = pg.ImageView()
imv.show()
imv.setImage(data)

Keyboard interaction

  • left/right arrows step forward/backward 1 frame when pressed, seek at 20fps when held.

  • up/down arrows seek at 100fps

  • pgup/pgdn seek at 1000fps

  • home/end seek immediately to the first/last frame

  • space begins playing frames. If time values (in seconds) are given for each frame, then playback is in realtime.

__init__(
parent=None,
name='ImageView',
view=None,
imageItem=None,
levelMode='mono',
discreteTimeLine=False,
roi=None,
normRoi=None,
*args,
)[source]#

By default, this class creates an ImageItem to display image data and a ViewBox to contain the ImageItem.

Parameters:
  • parent (QWidget) – Specifies the parent widget to which this ImageView will belong. If None, then the ImageView is created with no parent.

  • name (str) – The name used to register both the internal ViewBox and the PlotItem used to display ROI data. See the name argument to ViewBox.__init__().

  • view (ViewBox or PlotItem) – If specified, this will be used as the display area that contains the displayed image. Any ViewBox, PlotItem, or other compatible object is acceptable. Note: to display axis ticks inside the ImageView, instantiate it with a PlotItem instance as its view:

    pg.ImageView(view=pg.PlotItem())
    
  • imageItem (ImageItem) – If specified, this object will be used to display the image. Must be an instance of ImageItem or other compatible object.

  • levelMode (str) – See the levelMode argument to HistogramLUTItem.__init__()

  • discreteTimeLine (bool) – Whether to snap to xvals / frame numbers when interacting with the timeline position.

  • roi (ROI) – If specified, this object is used as ROI for the plot feature. Must be an instance of ROI.

  • normRoi (ROI) – If specified, this object is used as ROI for the normalization feature. Must be an instance of ROI.

autoLevels()[source]#

Set the min/max intensity levels automatically to match the image data.

autoRange()[source]#

Auto scale and pan the view around the image such that the image fills the view.

close()[source]#

Closes the widget nicely, making sure to clear the graphics scene and release memory.

export(
fileName,
)[source]#

Export data from the ImageView to a file, or to a stack of files if the data is 3D. Saving an image stack will result in index numbers being added to the file name. Images are saved as they would appear onscreen, with levels and lookup table applied.

getHistogramWidget()[source]#

Return the HistogramLUTWidget for this ImageView

getImageItem()[source]#

Return the ImageItem for this ImageView.

getProcessedImage()[source]#

Returns the image data after it has been processed by any normalization options in use.

getRoiPlot()[source]#

Return the ROI PlotWidget for this ImageView

getView()[source]#

Return the ViewBox (or other compatible object) which displays the ImageItem

jumpFrames(
n,
)[source]#

Move video frame ahead n frames (may be negative)

nframes()[source]#
Returns:

The number of frames in the image data.

Return type:

int

normalize(
image,
)[source]#

Process image using the normalization options configured in the control panel.

This can be repurposed to process any data through the same filter.

play(
rate=None,
)[source]#

Begin automatically stepping frames forward at the given rate (in fps). This can also be accessed by pressing the spacebar.

quickMinMax(
data,
)[source]#

Estimate the min/max values of data by subsampling. Returns [(min, max), …] with one item per channel

setColorMap(
colormap,
)[source]#

Set the color map.

Parameters:

colormap (ColorMap) – The ColorMap to use for coloring images.

setCurrentIndex(
ind,
)[source]#

Set the currently displayed frame index.

setHistogramLabel(
text=None,
**kwargs,
)[source]#

Set the label text of the histogram axis similar to AxisItem.setLabel()

setImage(
img,
autoRange=True,
autoLevels=True,
levels=None,
axes=None,
xvals=None,
pos=None,
scale=None,
transform=None,
autoHistogramRange=True,
levelMode=None,
)[source]#

Set the image to be displayed in the widget.

Parameters:
  • img (numpy.ndarray) – The image to be displayed. See ImageItem.setImage() and notes below.

  • autoRange (bool) – Whether to scale/pan the view to fit the image.

  • autoLevels (bool) – Whether to update the white/black levels to fit the image.

  • levels (tuple) – (min, max) white and black level values to use.

  • axes (dict) – Dictionary indicating the interpretation for each axis. This is only needed to override the default guess. Format is:

    {'t':0, 'x':1, 'y':2, 'c':3};
    
  • xvals (numpy.ndarray) – 1D array of values corresponding to the first axis in a 3D image. For video, this array should contain the time of each frame.

  • pos – Change the position of the displayed image

  • scale – Change the scale of the displayed image

  • transform – Set the transform of the displayed image. This option overrides pos and scale.

  • autoHistogramRange (bool) – If True, the histogram y-range is automatically scaled to fit the image data.

  • levelMode (str) – If specified, this sets the user interaction mode for setting image levels. Options are ‘mono’, which provides a single level control for all image channels, and ‘rgb’ or ‘rgba’, which provide individual controls for each channel.

Notes

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():

imageview.setImage(imagedata.T)

This requirement can be changed by the imageAxisOrder global configuration option.

setLevels(
*args,
**kwds,
)[source]#

Set the min/max (bright and dark) levels.

See HistogramLUTItem.setLevels.

setPredefinedGradient(
name,
)[source]#

Set one of the gradients defined in GradientEditorItem. Currently available gradients are: ‘thermal’, ‘flame’, ‘yellowy’, ‘bipolar’, ‘spectrum’, ‘cyclic’, ‘greyclip’, ‘grey’, ‘viridis’, ‘inferno’, ‘plasma’, ‘magma’, ‘turbo’

timeIndex(
slider,
)[source]#
Returns:

  • int – The index of the frame closest to the timeline slider.

  • float – The time value of the slider.