Image Visualiser#

class platipy.imaging.visualisation.visualiser.ImageVisualiser(image, cut=None, axis='ortho', window=None, figure_size_in=10, limits=None, colormap=<matplotlib.colors.LinearSegmentedColormap object>, origin='normal', projection=False)#

Bases: object

Class to assist with visualising images and overlaying contours, scalars and bounding boxes.

add_bounding_box(bounding_box, name=None, color='r', linewidth=2)#

Add a bounding box to draw.

Parameters:
  • bounding_box (dict|list|tuple|sitk.Image) – Dictionary of bounding boxes where list key is the name of the bounding box. If list or tuple then pass bounding box in format (x, y, z, w, h, d). If sitk.Image then mask is assumed and bounding box around this mask is used.

  • name (list, optional) – Name of this bounding box if bounding_box is list, tuple or sitk.Image. Defaults to None.

  • color (str|tuple|list, optional) – The color to use when drawing the bounding box(es). Defaults to None.

  • linewidth (int, optional) – The line width of the bounding box(es). Defaults to 2.

Raises:

ValueError – Raised if input is not a list or tuple of length 6 or and sitk.Image.

add_comparison_overlay(image, name=None, color_rotation=0.35)#

Overlay a comparison image on the existing image

Parameters:
  • sitk.Image) (image) – Image (will be displayed as a comparison).

  • name (str, optional) – Name to give the image. Defaults to None.

  • color_rotation (float, optional) – Defines the hue of the original image (0 - 0.5).

Raises:

ValueError – Comparison overlay must be of type sitk.Image.

add_contour(contour, name=None, color=None, colormap=<matplotlib.colors.LinearSegmentedColormap object>, linewidth=2, linestyle='solid', show_legend=True)#

Add a contour as overlay

Parameters:
  • contour (sitk.Image|dict) – Contour mask or dict containing contour masks.

  • name (str, optional) – Name to give the contour (only used if passing sitk.Image as contour). Defaults to None.

  • color (str|tuple|list, optional) – The color to use when drawing the contour(s). Defaults to None.

Raises:
  • ValueError – Contour must be dict of sitk.Image.

  • ValueError – If passing a dict for contour, all values must be sitk.Image.

add_scalar_overlay(scalar_image, name=None, colormap=<matplotlib.colors.LinearSegmentedColormap object>, alpha=0.75, min_value=False, max_value=False, discrete_levels=False, show_as_contours=False, mid_ticks=False, show_colorbar=True, norm=None, projection=False)#

Overlay a scalar image on to the existing image

Parameters:
  • sitk.Image|dict) (scalar_image) – Scalar image or dict containing scalar images.

  • name (str, optional) – Name to give the scalar image (only used if passing sitk.Image as scalar image). Defaults to None.

  • colormap (matplotlib.colors.Colormap, optional) – The colormap to be used when overlaying this scalar image. Defaults to matplotlib.colormaps.get_cmap(“cubehelix”).

  • alpha (float, optional) – Alpha to apply to overlay. Defaults to 0.75.

  • min_value (float, optional) – Values below this value aren’t rendered. Defaults to 0.1.

Raises:
  • ValueError – Scalar overlay must be dict of sitk.Image.

  • ValueError – If passing a dict for contour, all values must be sitk.Image.

add_vector_overlay(vector_image, min_value=False, max_value=False, colormap=<matplotlib.colors.ListedColormap object>, discrete_levels=False, mid_ticks=False, alpha=0.75, arrow_scale=1, arrow_width=1, subsample=8, color_function='magnitude', show_colorbar=True, name=None)#

Overlay a vector field on to the existing image

Parameters:
  • sitk.Image|dict) (vector_image) – Vector image (will be displayed as ).

  • name (str, optional) – Name to give the vector field (only used if passing sitk.Image as vector field). Defaults to None.

  • colormap (matplotlib.colors.Colormap, optional) – The colormap to be used when overlaying this vector field. Defaults to matplotlib.colormaps.get_cmap(“inferno”).

  • alpha (float, optional) – Alpha to apply to overlay vectors. Defaults to 0.75.

  • arrow_scale (float, optional) – Relative scaling of vectors. Defaults to 1.

  • arrow_width (float, optional) – Width of vector field arrow. Defaults to 1.

  • subsample (int, optional) – Defines to subsampling ratio of displayed vectors. Defaults to 8.

  • color_function (str, optional) – Determines how vectors are colored. Options: ‘perpendicular’ - vectors colored by perpendicular value ‘magnitude’ - vectors colored by magnitude.

Raises:

ValueError – Vector overlay must be of type sitk.Image.

clear()#

Clear all overlays

set_limits_from_label(label, expansion=2)#

Sets the limits of the axes to the bounds of the given label.

Parameters:
  • label (sitk.Image) – The label around which to set the limits

  • expansion (list | float, optional) – Expansion (in mm) around the label. Defaults to 2.

show(interact=False)#

Render the image with all overlays