Image¶
ImageView¶
-
class
datavis.views.
ImageView
(model=None, **kwargs)¶ This widget provides functionality for displaying images provided by a
ImageModel
.This class also allows to perform basic display operations over the data that is being displayed such as: rotations, zoom, drag and flips, among others.
- Example of use:
imageView = datavis.views.ImageView(parent=None, border_color=’#FFAA33’) d = pyqtgraph.gaussianFilter(np.random.normal(size=(512, 512)), (5, 5)) imgModel = dv.models.ImageModel(data) imageView.setModel(imgModel)
-
__init__
(model=None, **kwargs)¶ Create a new ImageView instance.
- Parameters
model –
ImageModel
instance that will be used to fetch the image data.- Keyword Arguments
parent – (QWidget) Is the parent widget to which this ImageView will belong. If None, then the ImageView is created with no parent.
toolBar – Bool value to specify if showing or hiding the toolbar. By default, the toolbar is visible.
roi – (Bool) If specified, this will be used to set visible the ROI button. False by default.
menu – (Bool) If specified, this will be used to set visible the Menu button. False by default.
histogram – (Bool) If specified, this will be used to set visible the Menu button. True by default.
fit – (Bool) If specified, this will be used to automatically auto-range the image whenever the view is resized. True by default.
autoFill – (Bool) This property holds whether the widget background is filled automatically. The color used is defined by the qtg.QPalette::Window color role from the widget’s palette. False by default.
hideButtons – (Bool) Hide/show the internal pg buttons. For example, the button used to center an image. False by default.
axisPos – (Bool) The axis position. Possible values: AXIS_TOP_LEFT, AXIS_TOP_RIGHT, AXIS_BOTTOM_RIGHT, AXIS_BOTTOM_LEFT
axisColor (str) – ‘#00FFAF’
axis – (Bool) Show/hide de view’s axes
labelX –
(dict) Dictionary with label properties, like CSS style:
labelStyle: (dict) CSS style. Example:
{'color': '#FFF', 'font-size': '14pt'}
labelText: (str) The label text
labelY – Same as labelX.
levels – (min, max) Pass the min and max range that will be used for image display. By default is None, so the data from the pixel values will be used. Passing a different range is useful for normalization of the slices in volumes.
preferredSize – (list of tuples). The first element is the image size and the second element is the preferred size.
maskParams –
Dictionary with mask-related params. Following are some possible values in this dict:
type:
ROI_CIRCLE (display a circular mask from center) or
ROI_RECT (display rectangular mask from center) or
CONSTANT (generate data mask with given constant value) or
DATA (just provide data mask as numpy array)
data: If the type is ROI_CIRCLE or ROI_RECT, it is the value of the radius of the mask. If type is CONSTANT it is the value of entire mask. Finally, if the type is DATA, this should be a numpy array with values of the mask.
color: (QColor or str) The color for the mask. Example: ‘#66212a55’ in ARGB format.
operation: What operation will be performed in the mask * NONE (the mask editor is not shown) or * ADD (add 1 values to the mask with the pen) or * REMOVE (add 0 values to the mask with the pen)
penSize: Size of the pen to be used, only relevant when not operation is not NONE (default 50px).
showHandles: (boolean) Enable/Disable the ROI handles
-
clear
()¶ Clear the view, setting a null image
-
eventFilter
(obj, event)¶ Filters events if this object has been installed as an event filter for the watched object.
- Parameters
obj – watched object
event – event
- Returns
True if this object has been installed, False otherwise.
-
export
(path=None, background=None, antialias=True, exportView=True)¶ Export the scene to the given path. Image - PNG is the default format. The exact set of image formats supported will depend on qtc.Qt libraries. However, common formats such as PNG, JPG, and TIFF are almost always available.
- Parameters
path – (str) The image path. If no path is specified, then a save dialog will be displayed
background – (str or qtg.QColor) The background color
antialias – (boolean) Use antialiasing for render the image
exportView – (boolean) If true, all the view area will be exported else export the image
-
fitToSize
()¶ Fit image to the widget size
-
getImageItem
()¶ Return the ImageItem object used for in pyqtgraph.ImageView. See pyqtgraph.ImageView.getImageItem
- Returns
pyqtgraph.ImageItem
-
getImageView
()¶ Return the internal pyqtgraph.ImageView
-
getMask
()¶ Return the current image mask data
-
getMaskColor
()¶ Return the mask color
-
getMaskData
()¶ Return the mask data. If mask-type is CONSTANT it is the value of entire mask. If the mask-type is DATA, this is a numpy array with values of the mask. If no mask has been configured, return None
-
getMaskImage
()¶ Return the mask created by the user using the Mask Creator Tools.
Returns: (u8bit numpy array) or None
-
getMaskSize
()¶ Return the image mask size. This function si valid only if a roi mask has been configured and return None in other case
-
getMaskType
()¶ Return the mask-type. Possible values are: ROI_CIRCLE, ROI_RECT, CONSTANT, DATA or None if no mask has been configured.
-
getPreferredSize
()¶ Returns a tuple (width, height), which represents the preferred dimensions to contain all the image
-
getScale
()¶ Return the image scale.
-
getToolBar
()¶ Get the left side toolbar.
-
getView
()¶ Returns the widget used for the internal pyqtgraph.ImageView to display image data.
- Returns: pyqtgraph.ViewBox (or other compatible object)
used by pyqtgraph.ImageView to display the image data
-
getViewBox
()¶ Return the pyqtgraph.ViewBox used for the internal pyqtgraph.ImageView. See pyqtgraph.ImageView
-
getViewRect
()¶ Returns the view rect area. See pyqtgraph.ViewBox.viewRect()
-
getViewSize
()¶ Returns the image view size.
Returns: A tupple (width, height) representing the view size
-
horizontalFlip
()¶ Flip the image horizontally (Image data is not modified).
-
imageModelChanged
()¶ Call this function when the image model has been modified externally
In this case, the ImageView will need to be notified so that the view can be updated.
-
isEmpty
()¶ Return True if the ImageView is empty
-
rotate
(angle)¶ Make a rotation according to the given angle. Does not modify the image. :param angle: (int) The angle(in degrees)
-
setAxisOrientation
(orientation)¶ Sets the axis orientation for this ImageView.
- Parameters
orientation –
Orientation of the axis. Possible values are:
AXIS_TOP_LEFT: axis in top-left
AXIS_TOP_RIGHT: axis in top-right
AXIS_BOTTOM_RIGHT: axis in bottom-right
AXIS_BOTTOM_LEFT: axis in bottom-left
-
setImageInfo
(**kwargs)¶ Set the image info that will be displayed.
- Keyword Arguments
text – (str) if passed, it will be used as the info to be displayed, if not, other arguments are considered
path – (str) the image path
format – (str) the image format
dataType – (str) the image data type
-
setImageMask
(**kwargs)¶ Set the mask to use in this ImageView.
If mask=None, the current mask will be removed.
- Keyword Arguments
type – ROI_CIRCLE (display a circular mask from center) or ROI_RECT (display rectangular mask from center) or CONSTANT (generate a data mask with given constant value) or DATA (just provide a data mask as numpy array)
color – (str or QColor) The color in #ARGB format. Example: #22AAFF00. Default value: ‘#2200FF55’
data – If the type is ROI_CIRCLE or ROI_RECT, it is the value of the radius of the mask. If type is CONSTANT it is the value of entire mask. Finally, if the type is DATA, this should be a numpy array with values of the mask.
showHandles – (boolean) Enable/Disable the ROI handles
-
setLevels
(levels)¶ Set levels for the display.
-
setMaskColor
(color)¶ Set the mask color.
- Parameters
color – (str) The color in #ARGB format. Example: #22AAFF00 or (qtg.QColor)
-
setModel
(imageModel, fitToSize=True)¶ Set the image model to be used for this ImageView.
- Parameters
imageModel – Input
ImageModel
-
setRoiMaskSize
(size)¶ Sets the size to the roi mask. If the ROI mask has been configured, then sets a new size to the roi mask. :param size: (int) The roi size
-
setRoiMaskSizeVisible
(visible)¶ Show or hide the TextItem used to display the roi mask size
-
setScale
(scale)¶ Set de image scale.
- Parameters
scale – (float) The new image scale.
-
setViewRect
(rect)¶ Set the current view rect. The view rect is the rect region that will be visible in the view.
- Parameters
rect – (QRect) The view rect
-
setXLink
(imageView)¶ Link the X axis to another ImageView.
- Parameters
imageView – (ImageView) The ImageView widget to be linked
-
setYLink
(imageView)¶ Link the Y axis to another ImageView. :param imageView: (ImageView) The ImageView widget to be linked
-
showHistogram
(visible=True)¶ Show or hide the histogram widget used by the internal pyqtgraph.ImageView.
-
showMenuButton
(visible=True)¶ Show or hide the menu button used by the internal pyqtgraph.ImageView
-
showRoiButton
(visible=True)¶ Show or hide the ROI button. used by the internal pyqtgraph.ImageView
-
showToolBar
(visible=True)¶ Show or hide the tool bar.
-
sigScaleChanged
¶ Signal emitted when the mask ROI size changed
-
updateImageScale
()¶ Update the image scale, calculating the current scale.
-
verticalFlip
()¶ Flips the image vertically. (Image data is not modified).
SlicesView¶
-
class
datavis.views.
SlicesView
(model, **kwargs)¶ This view can be used when displaying 3D data: (a) a single volume (x, y, z, 1) (b) stacks of particles (x, y, 1, n). In the case (b) for particles, usually the gallery view will be preferred, but for movies (stacks of frames), this view is very useful since these are big images and will take much memory loading all of them at once.
-
__init__
(model, **kwargs)¶ Construct an SlicesView instance. SlicesView use an
ImageView
to display the slices, see ImageView class for initialization params.- Parameters
model – The
SlicesModel
- Keyword Arguments
parent – (QWidget) Specifies the parent widget to which this ImageView will belong. If None, then the SlicesView is created with no parent.
text – (str) Text to be display in the slider.
currentValue – (int) The index (starting at 1) of the initial slice.
imageViewKwargs – The
ImageView
arguments
-
clear
()¶ Clear the view
-
getPreferredSize
()¶ Returns a tuple (width, height), which represents the preferred dimensions to contain all the data.
-
getRange
()¶ Returns a tuple (min, max) with the slices range.
-
getScale
()¶ Return the current scale
-
getText
()¶ Returns the label text for the internal slider
-
getValue
()¶ Returns the value of the current slice.
-
setModel
(model, **kwargs)¶ Set the
SlicesModel
- Parameters
model – The model or None for clear the view
- Keyword Arguments
normalize – (bool) If true, set the ImageView levels
slice – (int) If not None, set this as the initial slice
-
setScale
(scale)¶ Set the image scale
- Parameters
scale – (float) The scale
-
setText
(text)¶ Set the label text for the internal slider
-
setValue
(value)¶ Set the current value to a different one.
-
MultiSliceView¶
-
class
datavis.views.
MultiSliceView
(parent, slicesKwargs, mode=3)¶ This view is currently used for displaying 3D volumes and it is composed by 3
SlicesView
and a custom 2D plot showing the axis and the slider position. This view is the default for Volumes.-
__init__
(parent, slicesKwargs, mode=3)¶ Create a new MultiSliceView instance
- Parameters
parent – (QWidget) Parent widget
slicesKwargs – (dict) A dict with keys of axis(AXIS_X, AXIS_Y, AXIS_Z) and values for the model for each axis. See
SlicesView
mode – (int) Specifies which axis will be visible. Possible values: AXIS_X, AXIS_Y, AXIS_Z, AXIS_XYZ
-
clear
()¶ Clear the view
-
fitToSize
()¶ Fit images to the widget size
-
getAxis
()¶ Returns the current axis
-
getMode
()¶ Return the current mode. Possible values: AXIS_X, AXIS_Y, AXIS_Z, AXIS_XYZ
-
getPreferredSize
()¶ Returns a tuple (width, height), which represents the preferred dimensions to contain all the data
-
getSliceView
(axis=None)¶ Return the
SlicesView
widget for the given axis
-
getText
(axis)¶ Returns the label text for the given axis
- Parameters
axis – (int) The axis. (AXIS_X or AXIS_Y or AXIS_Z)
Returns: (str) The label text
- Raises
Exception If the axis is not anyone of the following – datavis.models.AXIS_X, datavis.models.AXIS_Y, datavis.models.AXIS_Z
-
getValue
(axis=None)¶ - Return the current slice index for the given axis.
(If axis=None, the last changed axis is used)
- Parameters
axis – AXIS_X or AXIS_Y or AXIS_Z
-
setAxis
(axis)¶ Sets the current axis. Updates the axis graphic.
- Parameters
axis – (int) The axis (AXIS_X or AXIS_Y or AXIS_Z)
-
setModel
(models, **kwargs)¶ Set the data models for display.
- Parameters
models – (tuple) The models (AXIS_X, AXIS_Y, AXIS_Z) for views or None for clear the view.
- Keyword Arguments
normalize – (bool) If True, each of the
SlicesView
will be normalized, levels of the image will be set all rangeslice – (int) Default slice
-
setScale
(scale)¶ Set the image scale for all axis :param scale: (float) The new image scale.
-
setValue
(value, axis=None)¶ Sets the slice value for the given axis. (If axis is None the last modified axis is used)
-
VolumeView¶
-
class
datavis.views.
VolumeView
(model, **kwargs)¶ View to display a volume and allows to switch between
MultiSliceView
andGalleryView
.In case of multiple volumes, this view could be extended with a way to select which volume to display.
-
__init__
(model, **kwargs)¶ Create a new VolumeView instance.
- Parameters
model – Input
VolumeModel
instance.- Keyword Arguments
parent – (QWidget) Parent widget.
cellSize – (int) The default cell size
maxCellSize – (int) The maximum value for cell size
minCellSize – (int) The minimum value for cell size
zoomUnits – (int) The zoom type for GalleryView cells: PIXEL_UNITS or PERCENT_UNITS
galleryKwargs – Configuration params for the internal
GalleryView
.slicesKwargs – Configuration params for the internal
MultiSliceView
.slicesMode – (int) Specifies which axis will be visible. Possible values: AXIS_X, AXIS_Y, AXIS_Z, AXIS_XYZ
-
clear
()¶ Clear the volume view
-
fitToSize
()¶ Fit the images to the widget size in MultiSliceView
-
getModel
()¶ Return the current model
-
setModel
(model)¶ Sets the
VolumeModel
- Raises
Exception if model is None. –
-
setView
(view)¶ Sets the current view: GALLERY or SLICES
-