platipy.imaging.visualisation package#

Submodules#

platipy.imaging.visualisation.animation module#

platipy.imaging.visualisation.utils module#

class platipy.imaging.visualisation.utils.VisualiseBoundingBox(bounding_box, name, color='r', linewidth=2)#

Bases: object

Class to represent the visualiation of a bounding box

class platipy.imaging.visualisation.utils.VisualiseComparisonOverlay(image, name, color_rotation=0.35)#

Bases: object

Class to represent the visualiation of a comparison image

class platipy.imaging.visualisation.utils.VisualiseContour(image, name, color=None, linewidth=2, linestyle='solid')#

Bases: object

Class to represent the visualiation of a contour

class platipy.imaging.visualisation.utils.VisualiseImage(image, aspect, interpolation, origin, colormap, clim)#

Bases: object

Class to represent visualisation of an image

class platipy.imaging.visualisation.utils.VisualiseScalarOverlay(image, name, 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)#

Bases: object

Class to represent the visualiation of a scalar overlay

class platipy.imaging.visualisation.utils.VisualiseVectorOverlay(image, min_value=False, max_value=False, colormap=<matplotlib.colors.LinearSegmentedColormap object>, discrete_levels=False, mid_ticks=False, alpha=0.75, arrow_scale=0.25, arrow_width=1, subsample=4, color_function='perpendicular', invert_field=True, show_colorbar=True, name='input')#

Bases: object

Class to represent the visualiation of a vector overlay

platipy.imaging.visualisation.utils.generate_comparison_colormix(image_list, arr_slice=None, window=(-250, 500), color_rotation=0.35)#
platipy.imaging.visualisation.utils.project_onto_arbitrary_plane(image, projection_name='mean', projection_axis=0, rotation_axis=[1, 0, 0], rotation_angle=0, default_value=-1000, resample_interpolation=2)#

[summary]

Parameters:
  • image ([type]) – [description]

  • projection_name (str, optional) – [description]. Defaults to “mean”.

  • projection_axis (int, optional) – [description]. Defaults to 0.

  • rotation_axis (list, optional) – [description]. Defaults to [1, 0, 0].

  • rotation_angle (int, optional) – [description]. Defaults to 0.

  • default_value (int, optional) – [description]. Defaults to -1000.

  • resample_interpolation (int, optional) – [description]. Defaults to 2.

Returns:

[description]

Return type:

[type]

platipy.imaging.visualisation.utils.reorientate_vector_field(axis, vector_ax, vector_cor, vector_sag, invert_field=True)#

Reorients vector field components for rendering This is necessary after converting from sitk.Image to np.array

Parameters:
  • axis (str) – One of “x”, “y” or “z”

  • vector_ax (np.array) – The first vector component (z)

  • vector_cor (np.array) – The second vector component (y)

  • vector_sag (np.array) – The third vector component (x)

Returns:

the re-oriented vector field components

Return type:

tuple

platipy.imaging.visualisation.utils.return_slice(axis, index)#

Prepares a slice tuple to use for extracting a slice for rendering

Parameters:
  • axis (str) – One of “x”, “y” or “z”

  • index (int) – The index of the slice to fetch

Returns:

can be used to extract a slice

Return type:

tuple

platipy.imaging.visualisation.utils.subsample_vector_field(axis, cut, subsample=1)#

Prepares a slice tuple to use for extracting a slice for rendering

Parameters:
  • axis (str) – One of “x”, “y” or “z”

  • cut (int) – The index of the image slice

  • subsample (int) – the subsample factor

Returns:

can be used to extract a vector field slice

Return type:

tuple

platipy.imaging.visualisation.utils.vector_image_grid(axis, vector_field_array, subsample=1)#

Prepares a grid for rendering a vector field on an image

Parameters:
  • axis (str) – One of “x”, “y” or “z”

  • vector_field_array (np.array) – the vector field array

  • subsample (int) – the subsample factor

Returns:

defines the 2 dimensional grid for displaying vectors

Return type:

tuple

platipy.imaging.visualisation.visualiser module#

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

draw_bounding_box_on_axes(ax, view, box, add_label=True)#
property image#
property labelmap#
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

platipy.imaging.visualisation.visualiser.logger = <Logger platipy.imaging.visualisation.visualiser (DEBUG)>#

This Python script comprises two contributions to the code base: 1) A bunch of helpful visualisation “helper” functions

  1. A visualisation class used to generate figures of images, contours, vector fields, and more!

Module contents#