viz

Module: viz.app

Horizon([tractograms, images, pams, ...])

apply_shader(hz, act)

Apply a shader to an actor (act) that access shared memory

horizon([tractograms, images, pams, ...])

Interactive medical visualization - Invert the Horizon!

Module: viz.gmem

GlobalHorizon()

Module: viz.horizon

Module: viz.horizon.app

Horizon([tractograms, images, pams, ...])

horizon([tractograms, images, pams, ...])

Interactive medical visualization - Invert the Horizon!

Module: viz.horizon.tab

Module: viz.horizon.tab.base

HorizonTab()

TabManager(tabs, win_size)

build_label(text[, font_size, bold])

Simple utility function to build labels

color_single_slider(slider)

color_double_slider(slider)

Module: viz.horizon.tab.cluster

ClustersTab(clusters_visualizer, threshold)

Module: viz.horizon.tab.peak

PeaksTab(peak_actor)

Module: viz.horizon.tab.roi

ROIsTab(contour_actors)

Module: viz.horizon.tab.slice

SlicesTab(slices_visualizer[, id])

Module: viz.horizon.visualizer

Module: viz.horizon.visualizer.cluster

ClustersVisualizer(show_manager, scene, ...)

Module: viz.horizon.visualizer.slice

SlicesVisualizer(interactor, scene, data[, ...])

Module: viz.panel

build_label(text[, font_size, bold])

Simple utility function to build labels

slicer_panel(scene, iren[, data, affine, ...])

Slicer panel with slicer included

Module: viz.plotting

plotting functions

compare_maps(fits, maps[, transpose, ...])

Compare one or more scalar maps for different fits or models.

compare_qti_maps(gt, fit1, fit2, mask[, ...])

Compare one or more qti derived maps obtained with different fitting routines.

bundle_shape_profile(x, shape_profile, std)

Plot bundlewarp bundle shape profile.

Module: viz.projections

Visualization tools for 2D projections of 3D functions on the sphere, such as ODFs.

sph_project(vertices, val[, ax, vmin, vmax, ...])

Draw a signal on a 2D projection of the sphere.

Module: viz.regtools

simple_plot(file_name, title, x, y, xlabel, ...)

Saves the simple plot with given x and y values

overlay_images(img0, img1[, title0, ...])

Plot two images one on top of the other using red and green channels.

draw_lattice_2d(nrows, ncols, delta)

Create a regular lattice of nrows x ncols squares.

plot_2d_diffeomorphic_map(mapping[, delta, ...])

Draw the effect of warping a regular lattice by a diffeomorphic map.

plot_slices(V[, slice_indices, fname])

Plot 3 slices from the given volume: 1 sagittal, 1 coronal and 1 axial

overlay_slices(L, R[, slice_index, ...])

Plot three overlaid slices from the given volumes.

Module: viz.streamline

show_bundles(bundles[, interactive, view, ...])

Render bundles to visualize them interactively or save them into a png.

viz_two_bundles(b1, b2, fname[, c1, c2, ...])

Render and plot two bundles to visualize them.

viz_vector_field(points_aligned, directions, ...)

Render and plot vector field.

viz_displacement_mag(bundle, offsets, fname)

Render and plot displacement magnitude over the bundle.

Horizon

class dipy.viz.app.Horizon(tractograms=None, images=None, pams=None, cluster=False, cluster_thr=15.0, random_colors=None, length_gt=0, length_lt=1000, clusters_gt=0, clusters_lt=10000, world_coords=True, interactive=True, out_png='tmp.png', recorded_events=None, return_showm=False, bg_color=(0, 0, 0), order_transparent=True, buan=False, buan_colors=None, roi_images=False, roi_colors=(1, 0, 0))

Bases: object

__init__(tractograms=None, images=None, pams=None, cluster=False, cluster_thr=15.0, random_colors=None, length_gt=0, length_lt=1000, clusters_gt=0, clusters_lt=10000, world_coords=True, interactive=True, out_png='tmp.png', recorded_events=None, return_showm=False, bg_color=(0, 0, 0), order_transparent=True, buan=False, buan_colors=None, roi_images=False, roi_colors=(1, 0, 0))

Interactive medical visualization - Invert the Horizon!

Parameters

tractogramssequence of StatefulTractograms

StatefulTractograms are used for making sure that the coordinate systems are correct

imagessequence of tuples

Each tuple contains data and affine

pamssequence of PeakAndMetrics

Contains peak directions and spherical harmonic coefficients

clusterbool

Enable QuickBundlesX clustering

cluster_thrfloat

Distance threshold used for clustering. Default value 15.0 for small animal data you may need to use something smaller such as 2.0. The threshold is in mm. For this parameter to be active cluster should be enabled.

random_colorsstring, optional

Given multiple tractograms and/or ROIs then each tractogram and/or ROI will be shown with a different color. If no value is provided, both the tractograms and the ROIs will have a different random color generated from a distinguishable colormap. If the effect should only be applied to one of the 2 types, then use the options ‘tracts’ and ‘rois’ for the tractograms and the ROIs respectively.

length_gtfloat

Clusters with average length greater than length_gt amount in mm will be shown.

length_ltfloat

Clusters with average length less than length_lt amount in mm will be shown.

clusters_gtint

Clusters with size greater than clusters_gt will be shown.

clusters_ltint

Clusters with size less than clusters_lt will be shown.

world_coordsbool

Show data in their world coordinates (not native voxel coordinates) Default True.

interactivebool

Allow user interaction. If False then Horizon goes on stealth mode and just saves pictures.

out_pngstring

Filename of saved picture.

recorded_eventsstring

File path to replay recorded events

return_showmbool

Return ShowManager object. Used only at Python level. Can be used for extending Horizon’s cababilities externally and for testing purposes.

bg_colorndarray or list or tuple

Define the background color of the scene. Default is black (0, 0, 0)

order_transparentbool

Default True. Use depth peeling to sort transparent objects. If True also enables anti-aliasing.

buanbool, optional

Enables BUAN framework visualization. Default is False.

buan_colorslist, optional

List of colors for bundles.

roi_imagesbool, optional

Displays binary images as contours. Default is False.

roi_colorsndarray or list or tuple, optional

Define the colors of the roi images. Default is red (1, 0, 0)

References

[Horizon_ISMRM19]

Garyfallidis E., M-A. Cote, B.Q. Chandio, S. Fadnavis, J. Guaje, R. Aggarwal, E. St-Onge, K.S. Juneja, S. Koudoro, D. Reagan, DIPY Horizon: fast, modular, unified and adaptive visualization, Proceedings of: International Society of Magnetic Resonance in Medicine (ISMRM), Montreal, Canada, 2019.

add_cluster_actors(scene, tractograms, threshold, enable_callbacks=True)

Add streamline actors to the scene

Parameters

scene : Scene tractograms : list

list of tractograms

thresholdfloat

Cluster threshold

enable_callbacksbool

Enable callbacks for selecting clusters

build_scene()
build_show(scene)
remove_cluster_actors(scene)

apply_shader

dipy.viz.app.apply_shader(hz, act)

Apply a shader to an actor (act) that access shared memory

Parameters

hz : GlobalHorizon instance act : fury.actor visual object

horizon

dipy.viz.app.horizon(tractograms=None, images=None, pams=None, cluster=False, cluster_thr=15.0, random_colors=None, bg_color=(0, 0, 0), order_transparent=True, length_gt=0, length_lt=1000, clusters_gt=0, clusters_lt=10000, world_coords=True, interactive=True, buan=False, buan_colors=None, roi_images=False, roi_colors=(1, 0, 0), out_png='tmp.png', recorded_events=None, return_showm=False)

Interactive medical visualization - Invert the Horizon!

Parameters

tractogramssequence of StatefulTractograms

StatefulTractograms are used for making sure that the coordinate systems are correct

imagessequence of tuples

Each tuple contains data and affine

pamssequence of PeakAndMetrics

Contains peak directions and spherical harmonic coefficients

clusterbool

Enable QuickBundlesX clustering

cluster_thrfloat

Distance threshold used for clustering. Default value 15.0 for small animal data you may need to use something smaller such as 2.0. The threshold is in mm. For this parameter to be active cluster should be enabled.

random_colorsstring

Given multiple tractograms and/or ROIs then each tractogram and/or ROI will be shown with different color. If no value is provided both the tractograms and the ROIs will have a different random color generated from a distinguishable colormap. If the effect should only be applied to one of the 2 objects, then use the options ‘tracts’ and ‘rois’ for the tractograms and the ROIs respectively.

bg_colorndarray or list or tuple

Define the background color of the scene. Default is black (0, 0, 0)

order_transparentbool

Default True. Use depth peeling to sort transparent objects. If True also enables anti-aliasing.

length_gtfloat

Clusters with average length greater than length_gt amount in mm will be shown.

length_ltfloat

Clusters with average length less than length_lt amount in mm will be shown.

clusters_gtint

Clusters with size greater than clusters_gt will be shown.

clusters_ltint

Clusters with size less than clusters_lt will be shown.

world_coordsbool

Show data in their world coordinates (not native voxel coordinates) Default True.

interactivebool

Allow user interaction. If False then Horizon goes on stealth mode and just saves pictures.

buanbool, optional

Enables BUAN framework visualization. Default is False.

buan_colorslist, optional

List of colors for bundles.

roi_imagesbool, optional

Displays binary images as contours. Default is False.

roi_colorsndarray or list or tuple, optional

Define the color of the roi images. Default is red (1, 0, 0)

out_pngstring

Filename of saved picture.

recorded_eventsstring

File path to replay recorded events

return_showmbool

Return ShowManager object. Used only at Python level. Can be used for extending Horizon’s cababilities externally and for testing purposes.

References

[Horizon_ISMRM19]

Garyfallidis E., M-A. Cote, B.Q. Chandio, S. Fadnavis, J. Guaje, R. Aggarwal, E. St-Onge, K.S. Juneja, S. Koudoro, D. Reagan, DIPY Horizon: fast, modular, unified and adaptive visualization, Proceedings of: International Society of Magnetic Resonance in Medicine (ISMRM), Montreal, Canada, 2019.

GlobalHorizon

class dipy.viz.gmem.GlobalHorizon

Bases: object

__init__()

Horizon

class dipy.viz.horizon.app.Horizon(tractograms=None, images=None, pams=None, cluster=False, cluster_thr=15.0, random_colors=None, length_gt=0, length_lt=1000, clusters_gt=0, clusters_lt=10000, world_coords=True, interactive=True, out_png='tmp.png', recorded_events=None, return_showm=False, bg_color=(0, 0, 0), order_transparent=True, buan=False, buan_colors=None, roi_images=False, roi_colors=(1, 0, 0))

Bases: object

__init__(tractograms=None, images=None, pams=None, cluster=False, cluster_thr=15.0, random_colors=None, length_gt=0, length_lt=1000, clusters_gt=0, clusters_lt=10000, world_coords=True, interactive=True, out_png='tmp.png', recorded_events=None, return_showm=False, bg_color=(0, 0, 0), order_transparent=True, buan=False, buan_colors=None, roi_images=False, roi_colors=(1, 0, 0))

Interactive medical visualization - Invert the Horizon!

Parameters

tractogramssequence of StatefulTractograms

StatefulTractograms are used for making sure that the coordinate systems are correct

imagessequence of tuples

Each tuple contains data and affine

pamssequence of PeakAndMetrics

Contains peak directions and spherical harmonic coefficients

clusterbool

Enable QuickBundlesX clustering

cluster_thrfloat

Distance threshold used for clustering. Default value 15.0 for small animal data you may need to use something smaller such as 2.0. The threshold is in mm. For this parameter to be active cluster should be enabled.

random_colorsstring, optional

Given multiple tractograms and/or ROIs then each tractogram and/or ROI will be shown with a different color. If no value is provided, both the tractograms and the ROIs will have a different random color generated from a distinguishable colormap. If the effect should only be applied to one of the 2 types, then use the options ‘tracts’ and ‘rois’ for the tractograms and the ROIs respectively.

length_gtfloat

Clusters with average length greater than length_gt amount in mm will be shown.

length_ltfloat

Clusters with average length less than length_lt amount in mm will be shown.

clusters_gtint

Clusters with size greater than clusters_gt will be shown.

clusters_ltint

Clusters with size less than clusters_lt will be shown.

world_coordsbool

Show data in their world coordinates (not native voxel coordinates) Default True.

interactivebool

Allow user interaction. If False then Horizon goes on stealth mode and just saves pictures.

out_pngstring

Filename of saved picture.

recorded_eventsstring

File path to replay recorded events

return_showmbool

Return ShowManager object. Used only at Python level. Can be used for extending Horizon’s cababilities externally and for testing purposes.

bg_colorndarray or list or tuple

Define the background color of the scene. Default is black (0, 0, 0)

order_transparentbool

Default True. Use depth peeling to sort transparent objects. If True also enables anti-aliasing.

buanbool, optional

Enables BUAN framework visualization. Default is False.

buan_colorslist, optional

List of colors for bundles.

roi_imagesbool, optional

Displays binary images as contours. Default is False.

roi_colorsndarray or list or tuple, optional

Define the colors of the roi images. Default is red (1, 0, 0)

References

[Horizon_ISMRM19]

Garyfallidis E., M-A. Cote, B.Q. Chandio, S. Fadnavis, J. Guaje, R. Aggarwal, E. St-Onge, K.S. Juneja, S. Koudoro, D. Reagan, DIPY Horizon: fast, modular, unified and adaptive visualization, Proceedings of: International Society of Magnetic Resonance in Medicine (ISMRM), Montreal, Canada, 2019.

build_scene()
build_show(scene)

horizon

dipy.viz.horizon.app.horizon(tractograms=None, images=None, pams=None, cluster=False, cluster_thr=15.0, random_colors=None, bg_color=(0, 0, 0), order_transparent=True, length_gt=0, length_lt=1000, clusters_gt=0, clusters_lt=10000, world_coords=True, interactive=True, buan=False, buan_colors=None, roi_images=False, roi_colors=(1, 0, 0), out_png='tmp.png', recorded_events=None, return_showm=False)

Interactive medical visualization - Invert the Horizon!

Parameters

tractogramssequence of StatefulTractograms

StatefulTractograms are used for making sure that the coordinate systems are correct

imagessequence of tuples

Each tuple contains data and affine

pamssequence of PeakAndMetrics

Contains peak directions and spherical harmonic coefficients

clusterbool

Enable QuickBundlesX clustering

cluster_thrfloat

Distance threshold used for clustering. Default value 15.0 for small animal data you may need to use something smaller such as 2.0. The threshold is in mm. For this parameter to be active cluster should be enabled.

random_colorsstring

Given multiple tractograms and/or ROIs then each tractogram and/or ROI will be shown with different color. If no value is provided both the tractograms and the ROIs will have a different random color generated from a distinguishable colormap. If the effect should only be applied to one of the 2 objects, then use the options ‘tracts’ and ‘rois’ for the tractograms and the ROIs respectively.

bg_colorndarray or list or tuple

Define the background color of the scene. Default is black (0, 0, 0)

order_transparentbool

Default True. Use depth peeling to sort transparent objects. If True also enables anti-aliasing.

length_gtfloat

Clusters with average length greater than length_gt amount in mm will be shown.

length_ltfloat

Clusters with average length less than length_lt amount in mm will be shown.

clusters_gtint

Clusters with size greater than clusters_gt will be shown.

clusters_ltint

Clusters with size less than clusters_lt will be shown.

world_coordsbool

Show data in their world coordinates (not native voxel coordinates) Default True.

interactivebool

Allow user interaction. If False then Horizon goes on stealth mode and just saves pictures.

buanbool, optional

Enables BUAN framework visualization. Default is False.

buan_colorslist, optional

List of colors for bundles.

roi_imagesbool, optional

Displays binary images as contours. Default is False.

roi_colorsndarray or list or tuple, optional

Define the color of the roi images. Default is red (1, 0, 0)

out_pngstring

Filename of saved picture.

recorded_eventsstring

File path to replay recorded events

return_showmbool

Return ShowManager object. Used only at Python level. Can be used for extending Horizon’s cababilities externally and for testing purposes.

References

[Horizon_ISMRM19]

Garyfallidis E., M-A. Cote, B.Q. Chandio, S. Fadnavis, J. Guaje, R. Aggarwal, E. St-Onge, K.S. Juneja, S. Koudoro, D. Reagan, DIPY Horizon: fast, modular, unified and adaptive visualization, Proceedings of: International Society of Magnetic Resonance in Medicine (ISMRM), Montreal, Canada, 2019.

HorizonTab

class dipy.viz.horizon.tab.base.HorizonTab

Bases: ABC

__init__()
abstract build(tab_id, tab_ui)
abstract property name

TabManager

class dipy.viz.horizon.tab.base.TabManager(tabs, win_size)

Bases: object

__init__(tabs, win_size)
reposition(win_size)
property tab_ui

build_label

dipy.viz.horizon.tab.base.build_label(text, font_size=16, bold=False)

Simple utility function to build labels

Parameters

text : str font_size : int bold : bool

Returns

label : TextBlock2D

color_single_slider

dipy.viz.horizon.tab.base.color_single_slider(slider)

color_double_slider

dipy.viz.horizon.tab.base.color_double_slider(slider)

ClustersTab

class dipy.viz.horizon.tab.cluster.ClustersTab(clusters_visualizer, threshold)

Bases: HorizonTab

__init__(clusters_visualizer, threshold)
build(tab_id, tab_ui)
property name

PeaksTab

class dipy.viz.horizon.tab.peak.PeaksTab(peak_actor)

Bases: HorizonTab

__init__(peak_actor)
build(tab_id, tab_ui)
property name

ROIsTab

class dipy.viz.horizon.tab.roi.ROIsTab(contour_actors)

Bases: HorizonTab

__init__(contour_actors)
build(tab_id, tab_ui)
property name

SlicesTab

class dipy.viz.horizon.tab.slice.SlicesTab(slices_visualizer, id=0)

Bases: HorizonTab

__init__(slices_visualizer, id=0)
build(tab_id, tab_ui)
property name

ClustersVisualizer

class dipy.viz.horizon.visualizer.cluster.ClustersVisualizer(show_manager, scene, tractograms, enable_callbacks=True)

Bases: object

__init__(show_manager, scene, tractograms, enable_callbacks=True)
add_cluster_actors(tract_idx, streamlines, thr, colors)
property centroid_actors
property cluster_actors
property lengths
recluster_tractograms(thr)
property sizes
property tractogram_clusters

SlicesVisualizer

class dipy.viz.horizon.visualizer.slice.SlicesVisualizer(interactor, scene, data, affine=None, world_coords=False, percentiles=[2, 98])

Bases: object

__init__(interactor, scene, data, affine=None, world_coords=False, percentiles=[2, 98])
change_volume(prev_idx, next_idx, intensities, visible_slices)
property data_shape
property intensities_range
register_picker_callback(callback)
property selected_slices
property slice_actors
property volume_max
property volume_min

build_label

dipy.viz.panel.build_label(text, font_size=18, bold=False)

Simple utility function to build labels

Parameters

text : str font_size : int bold : bool

Returns

label : TextBlock2D

slicer_panel

dipy.viz.panel.slicer_panel(scene, iren, data=None, affine=None, world_coords=False, pam=None, mask=None, mem=<dipy.viz.gmem.GlobalHorizon object>)

Slicer panel with slicer included

Parameters

scene : Scene iren : Interactor data : 3d ndarray affine : 4x4 ndarray world_coords : bool

If True then the affine is applied.

peaksPeaksAndMetrics

Default None

mem :

Returns

panel : Panel

compare_maps

dipy.viz.plotting.compare_maps(fits, maps, transpose=None, fit_labels=None, map_labels=None, fit_kwargs=None, map_kwargs=None, filename=None)

Compare one or more scalar maps for different fits or models.

Parameters

fitslist

List of fits to be compared.

mapslist

Names of attributes to be compared. Default: ‘rtop’.

transposebool, optional

If False, different fits are placed on different rows and different maps on different columns. If True, the order is transposed. If None, the figures are placed such that there are more columns than rows. Default: None.

fit_labelslist, optional

Labels for the different fitting routines. If None the fits are labeled by number. Default: None.

map_labelslist, optional

Labels for the different attributes. If None the attribute names are used. Default: None.

fit_kwargslist or dict, optional

A dict or list of dicts with imshow options for each fitting routine. The dicts are passed to imshow as keyword-argument pairs. Default: {}.

map_kwargslist or dict, optional

A dict or list of dicts with imshow options for each MAP-MRI scalar. The dicts are passed to imshow as keyword-argument pairs. Default: {}.

filenamestring, optional

Filename where the image will be saved. Default: None.

compare_qti_maps

dipy.viz.plotting.compare_qti_maps(gt, fit1, fit2, mask, maps=('fa', 'ufa'), fitname=('QTI', 'QTI+'), xlimits=([0, 1], [0.4, 1.5]), disprange=([0, 1], [0, 1]), slice=13)

Compare one or more qti derived maps obtained with different fitting routines.

Parameters

gtqti fit object

The qti fit to be considered as ground truth

fit1qti fit object

First qti fit to be compared

fit2qti fit object

Second qti fit to be compared

masknp.ndarray

Boolean array indicating which voxels to retain for comparing the values

mapsarray-like, optional

QTI invariants to be compared

fitnamearray-like, optional

Names of the used QTI fitting routines

xlimitsarray-like, optional

X-Axis limits for the histograms visualization

disprangearray-like, optional

Display range for maps

sliceint, optional

Axial brain slice to be visualized

bundle_shape_profile

dipy.viz.plotting.bundle_shape_profile(x, shape_profile, std)

Plot bundlewarp bundle shape profile.

Parameters

xnp.ndarray

Integer array containing x-axis

shape_profilenp.ndarray

Float array containing bundlewarp displacement magnitudes along the length of the bundle

stdnp.ndarray

Float array containing standard deviations

sph_project

dipy.viz.projections.sph_project(vertices, val, ax=None, vmin=None, vmax=None, cmap=None, cbar=True, tri=False, boundary=False, **basemap_args)

Draw a signal on a 2D projection of the sphere.

Parameters

vertices(N,3) ndarray

unit vector points of the sphere

val: (N) ndarray

Function values.

axmpl axis, optional

If specified, draw onto this existing axis instead.

vmin, vmaxfloats

Values to cut the z

cmap : mpl colormap

cbar: Whether to add the color-bar to the figure

triang : Whether to display the plot triangulated as a pseudo-color plot.

boundary : Whether to draw the boundary around the projection in a black line

Returns

axaxis

Matplotlib figure axis

Examples

>>> from dipy.data import default_sphere
>>> verts = default_sphere.vertices
>>> ax = sph_project(verts.T, np.random.rand(len(verts.T))) 

simple_plot

dipy.viz.regtools.simple_plot(file_name, title, x, y, xlabel, ylabel)

Saves the simple plot with given x and y values

Parameters

file_namestring

file name for saving the plot

titlestring

title of the plot

xinteger list

x-axis values to be plotted

yinteger list

y-axis values to be plotted

xlabelstring

label for x-axis

ylablestring

label for y-axis

overlay_images

dipy.viz.regtools.overlay_images(img0, img1, title0='', title_mid='', title1='', fname=None, **fig_kwargs)

Plot two images one on top of the other using red and green channels.

Creates a figure containing three images: the first image to the left plotted on the red channel of a color image, the second to the right plotted on the green channel of a color image and the two given images on top of each other using the red channel for the first image and the green channel for the second one. It is assumed that both images have the same shape. The intended use of this function is to visually assess the quality of a registration result.

Parameters

img0array, shape(R, C)

the image to be plotted on the red channel, to the left of the figure

img1array, shape(R, C)

the image to be plotted on the green channel, to the right of the figure

title0string (optional)

the title to be written on top of the image to the left. By default, no title is displayed.

title_midstring (optional)

the title to be written on top of the middle image. By default, no title is displayed.

title1string (optional)

the title to be written on top of the image to the right. By default, no title is displayed.

fnamestring (optional)

the file name to write the resulting figure. If None (default), the image is not saved.

fig_kwargs: extra parameters for saving figure, e.g. dpi=300.

draw_lattice_2d

dipy.viz.regtools.draw_lattice_2d(nrows, ncols, delta)

Create a regular lattice of nrows x ncols squares.

Creates an image (2D array) of a regular lattice of nrows x ncols squares. The size of each square is delta x delta pixels (not counting the separation lines). The lines are one pixel width.

Parameters

nrowsint

the number of squares to be drawn vertically

ncolsint

the number of squares to be drawn horizontally

deltaint

the size of each square of the grid. Each square is delta x delta pixels

Returns

latticearray, shape (R, C)

the image (2D array) of the segular lattice. The shape (R, C) of the array is given by R = 1 + (delta + 1) * nrows C = 1 + (delta + 1) * ncols

plot_2d_diffeomorphic_map

dipy.viz.regtools.plot_2d_diffeomorphic_map(mapping, delta=10, fname=None, direct_grid_shape=None, direct_grid2world=-1, inverse_grid_shape=None, inverse_grid2world=-1, show_figure=True, **fig_kwargs)

Draw the effect of warping a regular lattice by a diffeomorphic map.

Draws a diffeomorphic map by showing the effect of the deformation on a regular grid. The resulting figure contains two images: the direct transformation is plotted to the left, and the inverse transformation is plotted to the right.

Parameters

mappingDiffeomorphicMap object

the diffeomorphic map to be drawn

deltaint, optional

the size (in pixels) of the squares of the regular lattice to be used to plot the warping effects. Each square will be delta x delta pixels. By default, the size will be 10 pixels.

fnamestring, optional

the name of the file the figure will be written to. If None (default), the figure will not be saved to disk.

direct_grid_shapetuple, shape (2,), optional

the shape of the grid image after being deformed by the direct transformation. By default, the shape of the deformed grid is the same as the grid of the displacement field, which is by default equal to the shape of the fixed image. In other words, the resulting deformed grid (deformed by the direct transformation) will normally have the same shape as the fixed image.

direct_grid2worldarray, shape (3, 3), optional

the affine transformation mapping the direct grid’s coordinates to physical space. By default, this transformation will correspond to the image-to-world transformation corresponding to the default direct_grid_shape (in general, if users specify a direct_grid_shape, they should also specify direct_grid2world).

inverse_grid_shapetuple, shape (2,), optional

the shape of the grid image after being deformed by the inverse transformation. By default, the shape of the deformed grid under the inverse transform is the same as the image used as “moving” when the diffeomorphic map was generated by a registration algorithm (so it corresponds to the effect of warping the static image towards the moving).

inverse_grid2worldarray, shape (3, 3), optional

the affine transformation mapping inverse grid’s coordinates to physical space. By default, this transformation will correspond to the image-to-world transformation corresponding to the default inverse_grid_shape (in general, if users specify an inverse_grid_shape, they should also specify inverse_grid2world).

show_figurebool, optional

if True (default), the deformed grids will be plotted using matplotlib, else the grids are just returned

fig_kwargs: extra parameters for saving figure, e.g. dpi=300.

Returns

warped_forwardarray

Image with the grid showing the effect of transforming the moving image to the static image. The shape will be direct_grid_shape if specified, otherwise the shape of the static image.

warped_backwardarray

Image with the grid showing the effect of transforming the static image to the moving image. Shape will be inverse_grid_shape if specified, otherwise the shape of the moving image.

Notes

The default value for the affine transformation is “-1” to handle the case in which the user provides “None” as input meaning “identity”. If we used None as default, we wouldn’t know if the user specifically wants to use the identity (specifically passing None) or if it was left unspecified, meaning to use the appropriate default matrix.

plot_slices

dipy.viz.regtools.plot_slices(V, slice_indices=None, fname=None, **fig_kwargs)

Plot 3 slices from the given volume: 1 sagittal, 1 coronal and 1 axial

Creates a figure showing the axial, coronal and sagittal slices at the requested positions of the given volume. The requested slices are specified by slice_indices.

Parameters

Varray, shape (S, R, C)

the 3D volume to extract the slices from

slice_indicesarray, shape (3,) (optional)

the indices of the sagittal (slice_indices[0]), coronal (slice_indices[1]) and axial (slice_indices[2]) slices to be displayed. If None, the middle slices along each direction are displayed.

fnamestring (optional)

the name of the file to save the figure to. If None (default), the figure is not saved to disk.

fig_kwargs: extra parameters for saving figure, e.g. dpi=300.

overlay_slices

dipy.viz.regtools.overlay_slices(L, R, slice_index=None, slice_type=1, ltitle='Left', rtitle='Right', fname=None, **fig_kwargs)

Plot three overlaid slices from the given volumes.

Creates a figure containing three images: the gray scale k-th slice of the first volume (L) to the left, where k=slice_index, the k-th slice of the second volume (R) to the right and the k-th slices of the two given images on top of each other using the red channel for the first volume and the green channel for the second one. It is assumed that both volumes have the same shape. The intended use of this function is to visually assess the quality of a registration result.

Parameters

Larray, shape (S, R, C)

the first volume to extract the slice from plotted to the left

Rarray, shape (S, R, C)

the second volume to extract the slice from, plotted to the right

slice_indexint (optional)

the index of the slices (along the axis given by slice_type) to be overlaid. If None, the slice along the specified axis is used

slice_typeint (optional)

the type of slice to be extracted: 0=sagittal, 1=coronal (default), 2=axial.

ltitlestring (optional)

the string to be written as the title of the left image. By default, no title is displayed.

rtitlestring (optional)

the string to be written as the title of the right image. By default, no title is displayed.

fnamestring (optional)

the name of the file to write the image to. If None (default), the figure is not saved to disk.

fig_kwargs: extra parameters for saving figure, e.g. dpi=300.

show_bundles

dipy.viz.streamline.show_bundles(bundles, interactive=True, view='sagital', colors=None, linewidth=0.3, save_as=None)

Render bundles to visualize them interactively or save them into a png.

The function allows to just render the bundles in an interactive plot or to export them into a png file.

Parameters

bundleslist

Bundles to be rendered.

interactiveboolean, optional

If True a 3D interactive rendering is created. Default is True.

viewstr, optional

Viewing angle. Supported options: ‘sagital’,’axial’ and ‘coronal’. Default is ‘sagital’.

colorslist, optional

Colors to be used for each bundle. If None default colors are used.

linewidthfloat, optional

Width of each rendered streamline. Default is 0.3.

save_asstr, optional

If not None rendered scene is stored in a png file with that name. Default is None.

viz_two_bundles

dipy.viz.streamline.viz_two_bundles(b1, b2, fname, c1=(1, 0, 0), c2=(0, 1, 0), interactive=False)

Render and plot two bundles to visualize them.

Parameters

b1Streamlines

Bundle one to be rendered.

b2Streamlines

Bundle two to be rendered.

fname: str

Rendered scene is stored in a png file with that name.

C1tuple, optional

Color to be used for first bundle. Default red.

C2tuple, optional

Color to be used for second bundle. Default green.

interactiveboolean, optional

If True a 3D interactive rendering is created. Default is True.

viz_vector_field

dipy.viz.streamline.viz_vector_field(points_aligned, directions, colors, offsets, fname, bundle=None, interactive=False)

Render and plot vector field.

Parameters

points_alignedList

List containing starting positions of vectors.

directionsList

List containing unitary directions of vectors.

colorsList

List containing colors for each vector.

offsetsList

List containing vector field modules.

fname: str

Rendered scene is stored in a png file with that name.

bundleStreamlines, optional

Bundle to be rendered with vector field (Default None).

interactiveboolean, optional

If True a 3D interactive rendering is created. Default is True.

viz_displacement_mag

dipy.viz.streamline.viz_displacement_mag(bundle, offsets, fname, interactive=False)

Render and plot displacement magnitude over the bundle.

Parameters

bundleStreamlines,

Bundle to be rendered.

offsetsList

List containing displacement magnitdues per point on the bundle.

fname: str

Rendered scene is stored in a png file with that name.

interactiveboolean, optional

If True a 3D interactive rendering is created. Default is True.