Display Image

A collection of useful functions and classes for image displaying. The functionalities have been designed to quickly display and analyse 3D images of CT and/or dose (or any other 3D quantity distribution) in jupyter, inlcuding the interactive mode.

fredtools.showSlice(ax, imgBack=None, imgFront=None, plane='XY', point=None, cmapBack='bone', cmapFront='jet', alphaFront=0.7, imgROIs=None, vmaxBack=None, vmaxFront=None, showLegend=True, fontsize=8, raiseWarning=True)

Display image slice in front of another image slice including contours.

The function displays on ax a plane going through point of a 3D image describing the front image overlapped on a slice of another image describing the background. It forms a simple wrapper to matplotlib.pyplot.imshow allowing for a quick display of a slice from a 3D image of signal (e.g. dose) and/or another image (e.g. CT).

Usually imgBack describes the CT and imgFront describes the dose or other signal. At least one variable, imgBack or imgFront must be given.

Parameters:
  • ax (AxesSubplot) – Axis to plot the image on.

  • imgBack (SimpleITK Image, optional) – Object of a SimpleITK 3D image describing the background image. (def. None)

  • imgFront (SimpleITK Image, optional) – Object of a SimpleITK 3D image describing the foreground image. (def. None)

  • plane (str, optional) – Plane to generate the 2D slice given as a string. See fredtools.getSlice for more details. (def. ‘XY’)

  • point (array_like, optional) – 3D point to generate the 2D slice through. If None then the centre of mass of the 3D foreground image (or background image if the foreground image is not given) will be used. (def. None)

  • cmapBack (string or matplotlib.colors.Colormap, optional) – Colormap to display the background image slice. (def. ‘bone’)

  • cmapFront (string or matplotlib.colors.Colormap, optional) – Colormap to display the foreground image slice. (def. ‘jet’)

  • imgROIs (SimpleITK Image or list of SimpleITK Images, optional) – An Instance of a SimpleITK image or list of instances of SimpleITK image objects describing a 3D mask. (def. None)

  • vmaxBack (scalar, optional) – Maximum value of the background image. If None then the maximum value of the 3D background image will be used. (def. None)

  • vmaxFront (scalar, optional) – Maximum value of the foreground dose map. If None then the maximum value of the 3D foreground image will be used. (def. None)

  • alphaFront (float, optional) – Alpha value pf the transparency of the foreground image. (def. 0.7)

  • showLegend (bool, optional) – Show legend of the ROI contour names if they exist. (def. True)

  • fontsize (scalar, optional) – Basic font size to be used for ticks, labels, legend, etc. (def. 8)

  • raiseWarning (bool, optional) – Raise warnings. (def. True)

Returns:

Foreground image (or background image if the foreground image is not given) attached to the axis ax.

Return type:

matplotlib.image.AxesImage

See also

showSlices

show three projections of a 3D image, also interactively.

getSlice

get a 2D image slice from SimpleITK Image.

class fredtools.showSlices(imgBack=None, imgFront=None, imgROIs=None, point=None, DCOFront=0.1, cmapBack='bone', cmapFront='jet', figsize=[15, 5], interactive=True)

Class to display three projections of 3D image slices on an another 3D image slices including contours.

The class creates a figure with three axes and displays three projections (planes), ‘XY’, ‘ZY’ and ‘X-Z’ (reversed Z), going through point, of a 3D image describing foreground overlapped on a background image. The class can display in an interactive mode exploiting ipywidgets functionality, allowing to move slices with a mouse well or move slices to the point when the mouse button is pressed. All those interactive features work with Shift pressed.

Usually imgBack describes the CT and imgFront describes the dose or other signal. At least one variable, imgBack or imgFront must be given.

Parameters:
  • imgBack (SimpleITK Image, optional) – Object of a 3D SimpleITK image describing the background image. (e.g. CT). (def. None)

  • imgFront (SimpleITK Image, optional) – Object of a 3D SimpleITK image describing the foreground image. (e.g. dose or gamma index map). (def. None)

  • imgROIs (SimpleITK Image or list of SimpleITK Images, optional) – An Instance of a SimpleITK image or list of instances of SimpleITK image objects describing a 3D mask. (def. None)

  • point (array_like, optional) – 3D point to generate the 2D slice through. If None then the centre of mass of the 3D foreground image (or the background image if the foreground is not given) will be used. (def. None)

  • DCOFront (float, optional) – Dose cut-off. The fraction of the maximum value of the foreground image below which the data will not be displayed. (def. 0.1)

  • cmapBack (string or matplotlib.colors.Colormap, optional) – Colormap to display the background image slice. (def. ‘bone’)

  • cmapFront (string or matplotlib.colors.Colormap, optional) – Colormap to display the foreground image slice. (def. ‘jet’)

  • figsize (2-element list, optional) – Width and height of the figure in inches. (def. [15, 5])

  • interactive (bool, optional) – Display in interactive mode using ipwidgets. Works only in jupyter. (def. True)