skrt.viewer.viewer module

Classes for displaying interactive medical image plots.

class skrt.viewer.viewer.OrthogViewer(nii=None, init_view='x-y', init_sl=None, init_pos=None, hu=[-300, 200], hu_width=500, hu_limits=None, hu_step=None, figsize=6, xlim=None, ylim=None, zlim=None, zoom=None, zoom_centre=None, zoom_ui=None, cmap=None, colorbar=False, colorbar_label=None, mpl_kwargs=None, dose_opacity=0.5, dose_kwargs=None, dose_range=None, dose_cmap=None, invert_mask=False, mask_color='black', jacobian_opacity=0.5, jacobian_kwargs=None, df_plot_type='grid', df_spacing=30, df_kwargs=None, struct_plot_type='contour', struct_opacity=None, struct_linewidth=2, struct_info=False, struct_info_dp=2, length_units=None, area_units=None, vol_units=None, struct_legend=False, legend_loc='lower left', init_struct=None, standalone=True, continuous_update=False, annotate_slice=None, save_as=None, show=True, major_ticks=None, minor_ticks=None, ticks_all_sides=False, no_axis_labels=False, **kwargs)

Bases: SingleViewer

SingleViewer with an orthgonal view displayed.

jump_to_struct()

Jump to mid slice of a structure.

make_image(*args, **kwargs)

Set up image object.

class skrt.viewer.viewer.QuickViewer(nii=None, title=None, mask=None, dose=None, structs=None, multi_structs=None, jacobian=None, df=None, share_slider=True, orthog_view=False, plots_per_row=None, match_axes=None, scale_in_mm=True, show_cb=False, show_overlay=False, show_diff=False, comparison=None, comparison_only=False, cb_splits=2, overlay_opacity=0.5, overlay_legend=False, legend_loc='lower left', translation=False, translation_file_to_overwrite=None, show_mse=False, dta_tolerance=5, dta_crit=1, diff_crit=15, suptitle=None, show=True, **kwargs)

Bases: object

Display multiple ViewerImages and comparison images.

__init__(nii=None, title=None, mask=None, dose=None, structs=None, multi_structs=None, jacobian=None, df=None, share_slider=True, orthog_view=False, plots_per_row=None, match_axes=None, scale_in_mm=True, show_cb=False, show_overlay=False, show_diff=False, comparison=None, comparison_only=False, cb_splits=2, overlay_opacity=0.5, overlay_legend=False, legend_loc='lower left', translation=False, translation_file_to_overwrite=None, show_mse=False, dta_tolerance=5, dta_crit=1, diff_crit=15, suptitle=None, show=True, **kwargs)

Display one or more interactive images.

Parameters:

niistring/nifti/array/list, default=None

Source of image data for each plot. If multiple plots are to be shown, this must be a list. Image sources can be any of:

  1. The path to a NIfTI or DICOM file;

  2. A nibabel.nifti1.Nifti1Image object;

  3. The path to a file containing a NumPy array;

  4. A NumPy array.

titlestring or list of strings, default=None

Custom title(s) to use for the image(s) to be displayed. If the number of titles given, n, is less than the number of images, only the first n figures will be given custom titles. If any titles are None, the name of the image file will be used as the title.

maskstring/nifti/array/list, default=None

Source(s) of array(s) to with which to mask each plot (see valid image sources for <nii>).

dosestring/nifti/array/list, default=None

Source(s) of dose field array(s) to overlay on each plot (see valid image sources for <nii>).

structsstr/list/dict, default=None

Locations of files from which to load structures masks. This argument can be any of:

  1. String:

    1. The path to a NIfTI file containing a structure mask;

    2. The path to a DICOM file containing structure contours;

    3. A wildcard matching one or more of the above file types;

    4. The path to a directory containing NIfTI or DICOM files;

    5. A wildcard matching one or more directories containing NIfTI or DICOM files.

    If the string is found to match a directory, the structures from all NIfTI or DICOM files inside that directory will be loaded.

    Structure names will be inferred from the filenames (NIfTI) or the structure names inside the file (DICOM) unless the user indicates otherwise in the <struct_names> parameter; e.g. a structure taken from a file called ‘right_parotid.nii.gz’ would automatically be called ‘right parotid’ in QuickViewer.

    If multiple loaded structures have the same names, QuickViewer will attempt to label each with a unique name in the UI:

    • If two structures named ‘heart’ are loaded from different directories dir1 and dir2, these will be labelled ‘Heart (dir1)’ and ‘Heart (dir2) in the UI.

    • If two structures named ‘heart’ are loaded from different files, file1.nii and file2.nii, these will be labelled ‘Heart (file1.nii)’ and ‘Heart (file2.nii)’ in the UI.

    However, if the <struct_legend> option is used, the structures will be labelled with the same name in the figure legend. See the labelling option below in part (3) or the <struct_names> option for more customisation.

  2. List:

    1. A list of any of the strings described above; all structure files found will be loaded.

    2. A list of pairs of paths to files containing structures to be compared to one another (see the <struct_comparison> option).

  3. Dict:

    Structure filepaths can be nested inside a dictionary, where the keys are labels which the user wishes to use to refer to structures in those files, and the values are any of the options listed above (except 2b).

    The label will be displayed in parentheses next to the structure names in the QuickViewer UI and structure legend.

    The <struct_names> and <struct_options> arguments can also be nested inside a dictionary if the user wants to apply different name and color options to the structures associated with different labels.

By default, each NIfTI file will be assumed to contain a single structure. To load multiple label masks from a single NIfTI file, add the string ‘multi:’ before the filepath, e.g.:

  • structs=’multi:my_file.nii’

or alternatively use the multi_structs parameter.

multi_structs : str/list/dict, default=None

Path(s) to file(s) from which to load multiple structure label masks per file.

Same as the <structs> argument, except each file specified in the <multi_structs> argument will be checked for different labels instead of being treated as a binary mask.

This can be used in conjunction with <structs> to load single masks from some files and multiple masks from others.

jacobianstring/nifti/array/list, default=None

Source(s) of jacobian determinant array(s) to overlay on each plot (see valid image sources for <nii>).

dfstring/nifti/array/list, default=None

Source(s) of deformation field(s) to overlay on each plot (see valid image sources for <nii>).

share_sliderbool, default=True

If True and all displayed images are in the same frame of reference, a single slice slider will be shared between all plots. If plots have different frames of reference, this option will be ignored.

orthog_viewbool, default=False

If True, an orthgonal view with an indicator line showing the current slice will be displayed alongside each plot.

plots_per_rowint, default=None

Number of plots to display before starting a new row. If None, all plots will be shown on a single row.

match_axesint/str, default=None

Method for adjusting axis limits. Can either be:

  • An integer n, where 0 < n < number of plots, or n is -1. The axes of all plots will be adjusted to be the same as those of plot n.

  • ‘all’/’both’: axes for all plots will be adjusted to cover the maximum range of all plots.

  • ‘overlap’: axes for all plots will be adjusted to just show the overlapping region.

  • ‘x’: same as ‘all’, but only applied to the current x axis. whatever the x axis is in the current view.

  • ‘y’: same as ‘all’, but only applied to the current y axis.

scale_in_mmbool, default=True

If True, the axis scales will be shown in mm instead of array indices.

show_cbbool, default=False

If True, a chequerboard image will be displayed. This option will only be applied if the number of images in <nii> is 2.

show_overlaybool, default=False

If True, a blue/red transparent overlaid image will be displayed. This option will only be applied if the number of images in <nii> is 2.

show_diffbool, default=False

If True, a the difference between two images will be shown. This option will only be applied if the number of images in <nii> is 2.

comparisonbool/str/list, default=None

Indicator for which type(s) of comparison image(s) to show. If True or ‘all’, a comparison image control by a dropdown menu with all comparison options will be loaded. Can also be a single string or list containing any combination of ‘all’, ‘chequerboard’, ‘overlay’, and ‘difference’ to plot those images in the desired order.

comparison_onlybool, False

If True, only comparison images (overlay/chequerboard/difference) will be shown. If no comparison options are selected, this parameter will be ignored.

cb_splitsint, default=2

Number of sections to show for chequerboard image. Minimum = 1 (corresponding to no chequerboard). Can later be changed interactively.

overlay_opacityfloat, default=0.5

Initial opacity of overlay. Can later be changed interactively.

overlay_legendbool default=False

If True, a legend will be displayed on the overlay plot.

legend_locstr, default=’lower left’

Location for any legends being displayed. Must be a valid matplotlib legend location.

translationbool, default=False

If True, widgets will be displayed allowing the user to apply a translation to the image and write this to an elastix transform file or plain text file.

translation_file_to_overwritestr, default=None

If not None and the <translation> option is used, this parameter will be used to populate the ‘Original’ and ‘Output’ file fields in the translation user interface.

show_msestr, default=None

Color for annotation of mean-squared-error if using comparison images. If None, no annotation will be added. Can be set to ‘True’ to use default colour (white).

dta_tolerancefloat, default=5

Tolerance to use when computing distance-to-agreement.

dta_critfloat, default=1

Critical value of distance-to-agreement to use when computing gamma index.

diff_critfloat, default=15

Critical value of difference to use when computing gamma index.

suptitlestring, default=None

Global title for all subplots. If None, no suptitle will be added.

showbool, default=True

If True, the plot will be displayed when the QuickViewer object is created. Otherwise, the plot can be displayed later via QuickViewer.show().

Keyword arguments:

timeseriesstr/list/dict, default=None

A series of image files taken at difference dates. This can be:

  1. The path to a directory containing multiple image files/ multiple directories each containing one image file;

  2. A list of paths to image files;

  3. A dict of dates and image files.

In cases (a) and (b), QuickViewer will attempt to infer the date first from the directory name, then from the filename if no valid date is found within the directory name. The date is taken from the first unbroken string of numbers that can be successfully parsed with dateutil.parser.

init_viewstring, default=’x-y’

Orientation at which to initially display the image(s).

init_slinteger, default=None

Slice number in the initial orientation direction at which to display the first image (can be changed interactively later). If None, the central slice will be displayed.

init_posfloat, default=None

Position in mm of the first slice to display. This will be rounded to the nearest slice. If <init_pos> and <init_idx> are both given, <init_pos> will override <init_idx> only if <scale_in_mm> is True.

hufloat/tuple, default=(-300, 200)

HU central value or range thresholds at which to display the image. Can later be changed interactively. If a single value is given, the HU range will be centred at this value with width given by <hu_width>. If a tuple is given, the HU range will be set to the two values in the tuple.

hu_widthfloat, default=500

Initial width of the HU window. Only used if <hu> is a single value.

hu_limitstuple, default=None

Full range to use for the HU slider. Can also set to ‘auto’ to detect min and max HU in the image. Defaults to (-2000, 2000).

hu_stepfloat, default=None

Step size to use for the HU slider. Defaults to 1 if the maximum HU is >= 10, otherwise 0.1.

figsizefloat/tuple, default=5

Height of the displayed figure in inches; figure width will be automatically generated from this. If None, the value in _default_figsize is used. Can also be a tuple containing (width, height) in inches in order to set width and height manually.

xlimtuple, default=None

Custom limits for the x axis. If one of the values in the tuple is None, the default x limits will be used.

ylimtuple, default=None

Custom limits for the y axis. If one of the values in the tuple is None, the default y limits will be used.

zlimtuple, default=None

Custom limits for the z axis. If one of the values in the tuple is None, the default z limits will be used.

cmapstr, default=None

Matplotlib colormap to use for image plotting. Supercedes any cmap included in <mpl_kwargs>.

colorbarbool, default=False

If True, colorbars will be displayed for HU, dose and Jacobian determinant.

colorbar_labelstr, default=None

Label for the colorbar and range slider. If None, will default to either ‘HU’ if an image file is given, or ‘Dose (Gy)’ if a dose file is given without an image.

mpl_kwargsdict, default=None

Dictionary of keyword arguments to pass to matplotlib.pyplot.imshow for the main image.See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html for options. Some useful keywords are:

  • ‘cmap’: colormap (default=’gray’).

  • ‘interpolation’: interpolation method (default=’antialiased’)

dose_opacityfloat, default=0.5

Initial opacity of the overlaid dose field. Can later be changed interactively.

dose_kwargsdict, default=None

Dictionary of keyword arguments to pass to matplotlib.pyplot.imshow for the dose image. See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html for options. Some useful keywords are:

  • ‘cmap’: colormap (default=’jet’).

  • ‘interpolation’: interpolation method (default=’antialiased’)

dose_rangelist, default=None

Min and max dose range to plot. This can also be set via the ‘vmin’ and ‘xmax’ keys in <dose_kwargs>; <dose_range> will take precedence if set.

dose_cmapstr, default=’jet’

Matplotlib colormap to use for dose field plotting. Supercedes any cmap in <dose_kwargs>

invert_maskbool, default=False

If True, any masks applied will be inverted.

mask_colormatplotlib color, default=’black’

color in which to display masked areas.

mask_thresholdfloat, default=0.5

Threshold on mask array; voxels with values below this threshold will be masked (or values above, if <invert_mask> is True).

jacobian_opacityfloat, default=0.5

Initial opacity of the overlaid jacobian determinant. Can later be changed interactively.

jacobian_kwargsdict, default=None

Dictionary of keyword arguments to pass to matplotlib.pyplot.imshow for the jacobian determinant. See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html for options. Some useful keywords are:

  • ‘cmap’: colormap (default=’seismic’).

  • ‘interpolation’: interpolation method (default=’antialiased’)

df_plot_typestr, default=’grid’

Option for initial plotting of deformation field. Can be ‘grid’, ‘quiver’, or ‘none’. Can later be changed interactively.

df_spacingint/tuple, default=30

Spacing between arrows on the quiver plot/gridlines on the grid plot of a deformation field. Can be a single value for spacing in all directions, or a tuple with values for (x, y, z). Dimensions are mm if <scale_in_mm> is True, or voxels if <scale_in_mm> is False.

df_kwargsdict, default=None

Dictionary of keyword arguments to pass to matplotlib when plotting the deformation field.

For grid plotting options, see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html. Some useful keywords are:

  • ‘linewidth’: default=2

  • ‘color’: default=’green’

For quiver plotting options, see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.quiver.html.

struct_plot_typestr, default=’contour’

Option for initial plot of structures. Can be ‘contour’, ‘mask’, ‘filled’, or ‘none’. Can later be changed interactively.

struct_opacityfloat, default=None

Initial opacity of structures when plotted as masks or filled contours. Can later be changed interactively. Default=1 for masks, 0.3 for filled contours.

struct_linewidthfloat, default=2

Initial linewidth of structures when plotted as contours. Can later be changed interactively.

struct_infobool, default=False

If True, the lengths and volumes of each structure will be displayed below the plot.

struct_info_dpint, default=2

Number of decimal places to show for floats in structure info and comparison tables.

length_unitsstr, default=None

Units in which to display the lengths of structures if <struct_info> if True. If None, units will be voxels if <scale_in_mm> is False, or mm if <scale_in_mm> is True. Options:

  1. ‘mm’

  2. ‘voxels’

area_unitsstr, default=None

Units in which to display the areas of structures if <struct_info> if True. If None, units will be voxels if <scale_in_mm> is False, or mm if <scale_in_mm> is True. Options:

  1. ‘mm’

  2. ‘voxels’

vol_unitsstr, default=None

Units in which to display the volumes of structures if <struct_info> if True. If None, units will be voxels if <scale_in_mm> is False, or mm^3 if <scale_in_mm> is True. Options:

  1. ‘mm’ for mm^3

  2. ‘voxels’ for voxels

  3. ‘ml’ for ml

struct_legendbool, default=False

If True, a legend will be displayed for any plot with structures.

init_structstr, default=None

If set to a structure name, the first slice to be displayed will be the central slice of that structure. This supercedes <init_pos> and <init_sl>.

struct_nameslist/dict, default=None

Custom names for structures.

If only one structure is to be loaded per file, this should be a dictionary where the keys are the desired custom names. The values of the dictionary can be either:

  1. A string containing the path of the file containing the structure to be renamed;

  2. A string containing the name of the structure to be renamed within a DICOM file;

  3. A string containing the automatically-generated name of the structure to be renamed (e.g. if the structure came from a file right_parotid.nii, its automatically generated name would be ‘right parotid’;

  4. A wildcard matching any of the above;

  5. A list of any of the above.

The list functionality allows the user to list multiple names that should be replaced by a single custom name, e.g. to handle cases where the same structure may have different names in different DICOM files.

If multiple structures are to be loaded from files (i.e. the <multi_structs> parameter is set, or paths in the <structs> parameter are prefixed with ‘multi:’) the <struct_names> parameter can either be:

  1. A list of names, where the Nth name in the list will be applied to the structure with mask label N in the structure array; or

  2. A dictionary where the keys are integers such that the name associated with key N will be applied to the structure with mask label N in the structure array.

Any of the options described above can also be nested into a dictionary where the keys are labels, if a label dictionary was used to load structures in the <structs> parameter. The nested options for each key will only be applied to structures whose label is that key.

struct_colorsdict, default=None

A dictionary mapping structure names to colors in which the structure will be displayed.

The dictionary keys should be either structure names or wildcards matching structure name(s). Note that structure names are inferred from the structure’s filename unless otherwise specified in the <struct_names> parameter.

The values of the dictionary can be any matplotlib colorlike object.

The color dictionary can also be nested into a dictionary where the keys are labels, if a label dictionary was used to load structures in the <structs> parameter. The nested options for each key will only be applied to structures whose label is that key.

structs_as_maskbool, default=True

If True, any loaded structures will be used to mask the image and dose field.

compare_structsbool, default=False

If True, slice-by-slice comparison metrics for pairs of structures will be displayed below the plot, and compared structures masks will be plotted with their overlapping region in a different colour.

The structures to compare can be set in three different ways:

  1. The user can explicitly indicate which structures should be compared by giving a list of lists for the <structs> argument, where each sublist contains exactly 2 filepaths corresponding to a pair of structures to be compared (see option 2b for <structs>).

  2. If only two structures are found for the filepaths/wildcards given in the <structs> option, these two structures will be compared.

  3. Otherwise, QuickViewer will search for pairs of loaded structures with the same name (either inferred from the filenames or specified manually by the user in the <struct_names> option). If no structures with matching names are found, no comparisons will be performed.

ignore_empty_structsbool, default=False

If True, any loaded structures array that only contains zeros will be ignored. If False, the names of empty structures will be displayed in the UI with ‘(empty)’ next to them.

ignore_unpaired_structsbool, default=False

If <structure_comparison> is True and structure pairs are automatically detected based on their names, this parameter determines whether any structures for which a matching name is not found should be displayed.

If True, only the pairs of structures with matching names will be shown. If False, all loaded structures will be shown regardless of whether they have a comparison match.

structs_to_keeplist, default=True

List of structure names or wildcards matching structures that you wish to load. All other structures will be ignored.

structs_to_ignorelist, default=True

List of structure names or wildcards matching structures that you wish to ignore.

autoload_structsbool, default=True

If True, structures will all be automatically loaded and plotted. If False, all structures will be initially turned off and will only be loaded if the user turns them on via the structure checkbox UI.

continuous_updatebool, default=False

If True, sliders in the UI will continuously update the figure as they are adjusted. Can cause lag.

annotate_slicestr, default=None

Color for annotation of slice number. Can be set to ‘True’ to use default colour (white). If None, no annotation will be added unless viewing outside jupyter, in which case the annotation will be white by default.

save_asstr, default=None

File to which the figure will be saved upon creation. If not None, a text input and button will be added to the UI, allowing the user to save the figure again at a later point.

zoomdouble/tuple, default=None

Amount between by which to zoom in (e.g. zoom=2 would give a 2x zoom). Can be a single value for all directions or a tuple of values for the (x, y, z) directions.

zoom_centretuple, default=None

Centrepoint of zooming in order (x, y, z). If any of the values are None, the midpoint of the image will be used in that direction.

zoom_uibool, default=None

If True, a UI for zooming will be displayed. Default is False unless structs are loaded, in which case default is True.

downsampleint/tuple, default=None

Factor by which to downsample an image. Can be a single value for all directions or a tuple of values in the (x, y, z) directions. For no downsampling, set values to None or 1, e.g. to downsample in the z direction only: downsample=(1, 1, 3).

affine4x4 array, default=None

Affine matrix to be used if image source(s) are NumPy array(s). If image sources are nifti file paths or nibabel objects, this parameter is ignored. If None, the arguments <voxel_sizes> and <origin> will be used to set the affine matrix.

voxel_sizestuple, default=(1, 1, 1)

Voxel sizes in mm, given in the order (y, x, z). Only used if image source is a numpy array and <affine> is None.

origintuple, default=(0, 0, 0)

Origin position in mm, given in the order (y, x, z). Only used if image source is a numpy array and <affine> is None.

major_ticksfloat, default=None

If not None, this value will be used as the interval between major tick marks. Otherwise, automatic matplotlib axis tick spacing will be used.

minor_ticksint, default=None

If None, no minor ticks will be plotted. Otherwise, this value will be the number of minor tick divisions per major tick interval.

ticks_all_sidesbool, default=False

If True, major (and minor if using) tick marks will be shown above and to the right hand side of the plot as well as below and to the left. The top/right ticks will not be labelled.

any_attr(attr)

Check whether any of this object’s viewers have a given attribute.

apply_translation()

Update the description of translation sliders to show translation in mm if the translation is changed.

find_translation_file(image)

Find an elastix translation file inside the directory of an image.

get_input_list(inp, allow_sublist=False)

Convert an input to a list with one item per image to be displayed.

load_comparison(comparison, show_cb, show_overlay, show_diff)

Create any comparison images.

make_comparison_ui()
make_fig()
make_lower_ui()

Make lower UI for structure checkboxes.

make_reset_zoom(viewer)

Make a reset zoom function for a given viewer that updates zoom without plotting, then plots afterwards.

make_translation_ui()
make_ui(share_slider)
match_axes(match_axes)

Adjust axes of plots to match if the match_axes option is set.

on_key(event)

Callbacks for key presses.

on_scroll(event)

Callbacks for scroll events.

plot(tight_layout=True, **kwargs)

Plot all images.

set_callbacks()

Set callbacks for scrolls and keypresses.

set_slider_widths()

Adjust widths of slider UI.

show(show=True)
write_translation_to_file(_)

Write current translation to file.

class skrt.viewer.viewer.SingleViewer(nii=None, init_view='x-y', init_sl=None, init_pos=None, hu=[-300, 200], hu_width=500, hu_limits=None, hu_step=None, figsize=6, xlim=None, ylim=None, zlim=None, zoom=None, zoom_centre=None, zoom_ui=None, cmap=None, colorbar=False, colorbar_label=None, mpl_kwargs=None, dose_opacity=0.5, dose_kwargs=None, dose_range=None, dose_cmap=None, invert_mask=False, mask_color='black', jacobian_opacity=0.5, jacobian_kwargs=None, df_plot_type='grid', df_spacing=30, df_kwargs=None, struct_plot_type='contour', struct_opacity=None, struct_linewidth=2, struct_info=False, struct_info_dp=2, length_units=None, area_units=None, vol_units=None, struct_legend=False, legend_loc='lower left', init_struct=None, standalone=True, continuous_update=False, annotate_slice=None, save_as=None, show=True, major_ticks=None, minor_ticks=None, ticks_all_sides=False, no_axis_labels=False, **kwargs)

Bases: object

Class for displaying a MultiImage with interactive elements.

__init__(nii=None, init_view='x-y', init_sl=None, init_pos=None, hu=[-300, 200], hu_width=500, hu_limits=None, hu_step=None, figsize=6, xlim=None, ylim=None, zlim=None, zoom=None, zoom_centre=None, zoom_ui=None, cmap=None, colorbar=False, colorbar_label=None, mpl_kwargs=None, dose_opacity=0.5, dose_kwargs=None, dose_range=None, dose_cmap=None, invert_mask=False, mask_color='black', jacobian_opacity=0.5, jacobian_kwargs=None, df_plot_type='grid', df_spacing=30, df_kwargs=None, struct_plot_type='contour', struct_opacity=None, struct_linewidth=2, struct_info=False, struct_info_dp=2, length_units=None, area_units=None, vol_units=None, struct_legend=False, legend_loc='lower left', init_struct=None, standalone=True, continuous_update=False, annotate_slice=None, save_as=None, show=True, major_ticks=None, minor_ticks=None, ticks_all_sides=False, no_axis_labels=False, **kwargs)
centre_at_struct(struct)

Set the current zoom centre to be the centre of a structure.

decrease_slice(n=1)

Decrease slice slider value by n slices.

get_hu_range()

Get vmin and vmax from HU sliders.

get_struct_html(struct)

Get HTML string containing name and colour for a structure.

get_struct_visibility()

Get list of currently visible structures from checkboxes.

increase_slice(n=1)

Increase slice slider value by n slices.

jump_to_struct()

Jump to the mid slice of a structure.

make_image(*args, **kwargs)

Set up image object.

make_lower_ui()
make_ui(vimage=None, share_slider=True)

Make Jupyter notebook UI. If vimage contains another SingleViewer instance, the UI will be taken from that image. If share_slider is False, independent HU and slice sliders will be created.

on_key(event)

Events run on keypress outside jupyter notebook.

on_scroll(event)

Events run on scroll outside jupyter notebook.

on_view_change()

Deal with a view change.

plot(**kwargs)

Plot a slice with current settings.

plot_image(im, **kwargs)

Plot a NiftiImage, reusing existing axes if outside a Jupyter notebook.

reset_zoom(_)

Reset zoom values to 1 and zoom centres to defaults.

save_fig(_=None)

Save figure to a file.

save_struct_comp_table(_)
save_struct_info_table(_)
save_table(df, filename, col_names=None)

Save the table inside a DataFrame.

set_ax_lims(xlim, ylim, zlim)

Set custom axis limits after image has been loaded.

set_callbacks()

Set up matplotlib callback functions for interactive plotting.

set_slice(view, sl)

Set the current slice number in a specific view.

set_slice_and_view()

Get the current slice and view to plot from the UI.

set_slice_from_pos(view, pos)

Set the current slice number from a position in mm.

show(show=True)

Display plot and UI.

show_in_notebook(show)

Display interactive output in a jupyter notebook.

slice_to_slider(sl, ax=None)

Convert a slice number to a slider value.

slider_to_sl(val, ax=None)

Convert a slider value to a slice number.

update_slice_slider()

Update the slice slider to show the axis corresponding to the current view, with value set to the last value used on that axis.

update_slice_slider_desc()

Update slice slider description to reflect current axis and position.

update_slider(slider, new_min, new_max, val)

Update slider min, max, and value without causing errors due to values outside range.

update_struct_comparisons()

Update structure comparison metrics to reflect the current view/slice.

update_struct_info()

Update structure info UI to reflect current view/slice.

update_struct_sliders()

Update struct sliders depending on current plot type.

update_zoom_sliders()

Update zoom sliders to reflect the current view.

skrt.viewer.viewer.in_notebook()
skrt.viewer.viewer.write_translation_to_file(output_file, dx=None, dy=None, dz=None, input_file=None, overwrite=False)

Open an existing elastix transformation file and create a new version with the translation parameters either replaced or added to the current user-created translation in the displayed figure.

Parameters:

output_filestring

Name of the output file to produce.

input_filestring, default=None

Path to an Elastix translation file to use as an input.

dx, dy, dzfloat, default=None

Translations (in mm) to add to the initial translations in the input_file.

overwritebool, default=False

If True, the shifts will be overwritten. If False, they will be added.