viz#

Module: viz.gmem#

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#

HorizonUIElement(visibility, selected_value, obj)

Dataclass to define properties of horizon ui elements.

HorizonTab()

Base for different tabs available in horizon.

TabManager(tabs, win_size, on_tab_changed, ...)

A Manager for tabs of the table panel.

build_label(text, *[, font_size, bold])

Simple utility function to build labels.

build_slider(initial_value, max_value, *[, ...])

Create a horizon theme based disk-knob slider.

build_checkbox(*[, labels, checked_labels, ...])

Create horizon theme checkboxes.

build_radio_button(*[, labels, ...])

Create horizon theme radio buttons.

build_switcher(*[, items, label, ...])

Create horizon theme switcher.

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, tab_name, ...)

Interaction tab for slice visualization.

Module: viz.horizon.tab.surface#

SurfaceTab(visualizer, tab_name, file_name)

Module: viz.horizon.util#

check_img_shapes(images)

Check if the images have same shapes.

check_img_dtype(images)

Check supplied image dtype.

show_ellipsis(text, text_size, available_size)

Apply ellipsis to the text.

unpack_image(img)

Unpack provided image data.

unpack_surface(surface)

Unpack surface data.

check_peak_size(pams, *[, ref_img_shape, ...])

Check shape of peaks.

Module: viz.horizon.visualizer#

Module: viz.horizon.visualizer.cluster#

ClustersVisualizer(show_manager, scene, ...)

Module: viz.horizon.visualizer.peak#

PeakActor(directions, indices, *[, values, ...])

FURY actor for visualizing DWI peaks.

PeaksVisualizer(pam, world_coords)

peak(peaks_dirs, *[, peaks_values, mask, ...])

Visualize peak directions as given from peaks_from_model function.

Module: viz.horizon.visualizer.slice#

SlicesVisualizer(interactor, scene, data, *)

Module: viz.horizon.visualizer.surface#

SurfaceVisualizer(surface, scene, color)

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.

image_mosaic(images, *[, ax_labels, ...])

Draw a mosaic of 2D images using pyplot.imshow().

Module: viz.projections#

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

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

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, *[, ...])

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, ...])

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.

GlobalHorizon#

class dipy.viz.gmem.GlobalHorizon[source]#

Bases: object

Horizon#

class dipy.viz.horizon.app.Horizon(*, tractograms=None, images=None, pams=None, surfaces=None, cluster=False, rgb=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), surface_colors=((1, 0, 0),))[source]#

Bases: object

Methods

build_scene

build_show

build_scene()[source]#
build_show(scene)[source]#

horizon#

dipy.viz.horizon.app.horizon(*, tractograms=None, images=None, pams=None, surfaces=None, cluster=False, rgb=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)[source]#

Interactive medical visualization - Invert the Horizon!

See [1] for further details about 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

surfacessequence of tuples

Each tuple contains vertices and faces

clusterbool

Enable QuickBundlesX clustering

rgb: bool, optional

Enable the color image.

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 capabilities externally and for testing purposes.

References

HorizonUIElement#

class dipy.viz.horizon.tab.base.HorizonUIElement(visibility: bool, selected_value: Any, obj: Any)[source]#

Bases: object

Dataclass to define properties of horizon ui elements.

obj: Any#
position = (0, 0)#
selected_value: Any#
size = ('auto', 'auto')#
visibility: bool#

HorizonTab#

class dipy.viz.horizon.tab.base.HorizonTab[source]#

Bases: ABC

Base for different tabs available in horizon.

Attributes:
actors

Name of the tab.

elements

list of underlying FURY ui elements in the tab.

name

Name of the tab.

tab_id

Id of the tab.

Methods

build(tab_id)

Build all the elements under the tab.

on_tab_selected()

Implement if require to update something while the tab becomes active.

abstract property actors#

Name of the tab.

abstract build(tab_id)[source]#

Build all the elements under the tab.

Parameters:
tab_idint

Id of the tab.

property elements#

list of underlying FURY ui elements in the tab.

abstract property name#

Name of the tab.

on_tab_selected()[source]#

Implement if require to update something while the tab becomes active.

property tab_id#

Id of the tab. Reference for Tab Manager to identify the tab.

Returns:
int

TabManager#

class dipy.viz.horizon.tab.base.TabManager(tabs, win_size, on_tab_changed, add_to_scene, *, remove_from_scene, sync_slices=False, sync_volumes=False, sync_peaks=False)[source]#

Bases: object

A Manager for tabs of the table panel.

Attributes:
tab_uiTabUI

FURY TabUI object.

Methods

reposition(win_size)

Reposition the tabs panel.

synchronize_slices(active_tab_id, x_value, ...)

Synchronize slicers for all the images and peaks.

synchronize_volumes(active_tab_id, value)

Synchronize volumes for all the images with volumes.

handle_text_overflows

handle_text_overflows()[source]#
reposition(win_size)[source]#

Reposition the tabs panel.

Parameters:
win_size(float, float)

size of the horizon window.

synchronize_slices(active_tab_id, x_value, y_value, z_value)[source]#

Synchronize slicers for all the images and peaks.

Parameters:
active_tab_id: int

tab_id of the action performing tab

x_value: float

x-value of the active slicer

y_value: float

y-value of the active slicer

z_value: float

z-value of the active slicer

synchronize_volumes(active_tab_id, value)[source]#

Synchronize volumes for all the images with volumes.

Parameters:
active_tab_idint

tab_id of the action performing tab

valuefloat

volume value of the active volume slider

property tab_ui#

FURY TabUI object.

build_label#

dipy.viz.horizon.tab.base.build_label(text, *, font_size=16, bold=False)[source]#

Simple utility function to build labels.

Parameters:
textstr
font_sizeint, optional
boldbool, optional
Returns:
labelTextBlock2D

build_slider#

dipy.viz.horizon.tab.base.build_slider(initial_value, max_value, *, min_value=0, length=450, line_width=3, radius=8, font_size=16, text_template='{value:.1f} ({ratio:.0%})', on_moving_slider=<function <lambda>>, on_value_changed=<function <lambda>>, on_change=<function <lambda>>, on_handle_released=<function <lambda>>, label='', label_font_size=16, label_style_bold=False, is_double_slider=False)[source]#

Create a horizon theme based disk-knob slider.

Parameters:
initial_valuefloat, (float, float)

Initial value(s) of the slider.

max_valuefloat

Maximum value of the slider.

min_valuefloat, optional

Minimum value of the slider.

lengthint, optional

Length of the slider.

line_widthint, optional

Width of the line on which the disk will slide.

radiusint, optional

Radius of the disk handle.

font_sizeint, optional

Size of the text to display alongside the slider (pt).

text_templatestr, callable, optional

If str, text template can contain one or multiple of the replacement fields: {value:}, {ratio:}. If callable, this instance of :class:LineSlider2D will be passed as argument to the text template function.

on_moving_slidercallable, optional

When the slider is interacted by the user.

on_value_changedcallable, optional

When value of the slider changed programmatically.

on_changecallable, optional

When value of the slider changed.

on_handle_released: callable, optional

When handle released.

labelstr, optional

Label to ui element for slider

label_font_sizeint, optional

Size of label text to display with slider

label_style_boldbool, optional

Is label should have bold style.

is_double_sliderbool, optional

True if the slider allows to adjust two values.

Returns:
labelHorizonUIElement

Slider label.

HorizonUIElement

Slider.

build_checkbox#

dipy.viz.horizon.tab.base.build_checkbox(*, labels=None, checked_labels=None, padding=1, font_size=16, on_change=<function <lambda>>)[source]#

Create horizon theme checkboxes.

Parameters:
labelslist(str), optional

List of labels of each option.

checked_labels: list(str), optional

List of labels that are checked on setting up.

paddingfloat, optional

The distance between two adjacent options element

font_sizeint, optional

Size of the text font.

on_changecallback, optional

When checkbox value changed

Returns:
checkboxHorizonUIElement

build_radio_button#

dipy.viz.horizon.tab.base.build_radio_button(*, labels=None, checked_labels=None, padding=1, font_size=16, on_change=<function <lambda>>)[source]#

Create horizon theme radio buttons.

Parameters:
labelslist(str), optional

List of labels of each option.

checked_labels: list(str), optional

List of labels that are checked on setting up.

paddingfloat, optional

The distance between two adjacent options element

font_sizeint, optional

Size of the text font.

on_changecallback, optional

When radio button value changed

Returns:
radioHorizonUIElement

build_switcher#

dipy.viz.horizon.tab.base.build_switcher(*, items=None, label='', initial_selection=0, on_prev_clicked=<function <lambda>>, on_next_clicked=<function <lambda>>, on_value_changed=<function <lambda>>)[source]#

Create horizon theme switcher.

Parameters:
itemslist, optional

dictionaries with keys ‘label’ and ‘value’. Label will be used to show it to user and value will be used for selection.

labelstr, optional

label for the switcher.

initial_selectionint, optional

index of the selected item initially.

on_prev_clickedcallback, optional

method providing a callback when prev value is selected in switcher.

on_next_clickedcallback, optional

method providing a callback when next value is selected in switcher.

on_value_changedcallback, optional

method providing a callback when either prev or next value selected in switcher.

Returns:
HorizonCombineElement(

label: HorizonUIElement, element(switcher): HorizonUIElement)

Notes

switcher: consists ‘obj’ which is an array providing FURY UI elements used.

ClustersTab#

class dipy.viz.horizon.tab.cluster.ClustersTab(clusters_visualizer, threshold)[source]#

Bases: HorizonTab

Attributes:
actors

All the actors in the visualizer.

centroid_actors

Centroid actors of the tractograms.

cluster_actors

Cluster actors of the tractograms.

elements

list of underlying FURY ui elements in the tab.

name

Title of the tab.

tab_id

Id of the tab.

Methods

build(tab_id)

Position the elements in the tab.

on_tab_selected()

Implement if require to update something while the tab becomes active.

property actors#

All the actors in the visualizer.

Returns:
list
build(tab_id)[source]#

Position the elements in the tab.

Parameters:
tab_idint

Id of the tab.

property centroid_actors#

Centroid actors of the tractograms.

Returns:
dict

various properties of centroids.

property cluster_actors#

Cluster actors of the tractograms.

Returns:
dict

various properties of clusters.

property name#

Title of the tab.

Returns:
str

PeaksTab#

class dipy.viz.horizon.tab.peak.PeaksTab(peak_actor)[source]#

Bases: HorizonTab

Attributes:
actors

actors controlled by tab.

elements

list of underlying FURY ui elements in the tab.

name

Name of the tab.

tab_id

Id of the tab.

Methods

build(tab_id)

Build all the elements under the tab.

on_tab_selected()

Trigger when tab becomes active.

update_slices(x_slice, y_slice, z_slice)

Updates slicer positions.

property actors#

actors controlled by tab.

Returns:
list

List of actors.

build(tab_id)[source]#

Build all the elements under the tab.

Parameters:
tab_idint

Id of the tab.

property name#

Name of the tab.

Returns:
str
on_tab_selected()[source]#

Trigger when tab becomes active.

update_slices(x_slice, y_slice, z_slice)[source]#

Updates slicer positions.

Parameters:
x_slice: float

x-value where the slicer should be placed

y_slice: float

y-value where the slicer should be placed

z_slice: float

z-value where the slicer should be placed

ROIsTab#

class dipy.viz.horizon.tab.roi.ROIsTab(contour_actors)[source]#

Bases: HorizonTab

Attributes:
actors

Actors controlled by tab.

elements

list of underlying FURY ui elements in the tab.

name

Title of the tab.

tab_id

Id of the tab.

Methods

build(tab_id)

Position the elements in the tab.

on_tab_selected()

Implement if require to update something while the tab becomes active.

property actors#

Actors controlled by tab.

Returns:
list
build(tab_id)[source]#

Position the elements in the tab.

Parameters:
tab_idint

Identifier for the tab. Index of the tab in TabUI.

property name#

Title of the tab.

Returns:
str

SlicesTab#

class dipy.viz.horizon.tab.slice.SlicesTab(slices_visualizer, tab_name, file_name, *, force_render=<function SlicesTab.<lambda>>)[source]#

Bases: HorizonTab

Interaction tab for slice visualization.

Attributes:
namestr

Name of the tab.

Methods

build(tab_id)

Build all the elements under the tab.

on_tab_selected()

Trigger when tab becomes active.

update_slices(x_slice, y_slice, z_slice)

Updates slicer positions.

update_volume(volume)

Updates volume based on passed volume.

property actors#

visualization actors controlled by tab.

build(tab_id)[source]#

Build all the elements under the tab.

Parameters:
tab_idint

Id of the tab.

property file_name#

Name of the file opened in the tab.

property name#

Name of the tab.

on_tab_selected()[source]#

Trigger when tab becomes active.

update_slices(x_slice, y_slice, z_slice)[source]#

Updates slicer positions.

Parameters:
x_slice: float

x-value where the slicer should be placed

y_slice: float

y-value where the slicer should be placed

z_slice: float

z-value where the slicer should be placed

update_volume(volume)[source]#

Updates volume based on passed volume.

Parameters:
volumefloat

value of where the volume slider should be placed

SurfaceTab#

class dipy.viz.horizon.tab.surface.SurfaceTab(visualizer, tab_name, file_name)[source]#

Bases: HorizonTab

Attributes:
actors

Actors controlled by this tab.

elements

list of underlying FURY ui elements in the tab.

name

Name of the tab.

tab_id

Id of the tab.

Methods

build(tab_id)

Build all the elements under the tab.

on_tab_selected()

Implement if require to update something while the tab becomes active.

property actors#

Actors controlled by this tab.

build(tab_id)[source]#

Build all the elements under the tab.

Parameters:
tab_idint

Id of the tab.

property name#

Name of the tab.

Returns:
str

check_img_shapes#

dipy.viz.horizon.util.check_img_shapes(images)[source]#

Check if the images have same shapes. It also provides details about the volumes are same or not. If the shapes are not equal it will return False for both shape and volume.

Parameters:
imageslist
Returns:
tuple

tuple[0] = True, if shapes are equal. tuple[1] = True, if volumes are equal.

check_img_dtype#

dipy.viz.horizon.util.check_img_dtype(images)[source]#

Check supplied image dtype.

If not supported numerical type, fallback to supported numerical types (either int32 or float 32). If non-numerical type, skip the data.

Parameters:
imageslist

Each image is tuple of (data, affine).

Returns:
list

Valid images from the provided images.

show_ellipsis#

dipy.viz.horizon.util.show_ellipsis(text, text_size, available_size)[source]#

Apply ellipsis to the text.

Parameters:
textstring

Text required to be check for ellipsis.

text_sizefloat

Current size of the text in pixels.

available_sizefloat

Size available to fit the text. This will be used to truncate the text and show ellipsis.

Returns:
string

Text after processing for ellipsis.

unpack_image#

dipy.viz.horizon.util.unpack_image(img)[source]#

Unpack provided image data.

Standard way to handle different value images.

Parameters:
imgtuple

An image can contain either (data, affine) or (data, affine, fname).

Returns:
tuple

If img with (data, affine) it will convert to (data, affine, None). Otherwise it will be passed as it is.

unpack_surface#

dipy.viz.horizon.util.unpack_surface(surface)[source]#

Unpack surface data.

Parameters:
surfacetuple

It either contains (vertices, faces) or (vertices, faces, fname).

Returns:
tuple

If surface with (vertices, faces) it will convert to (vertices, faces, None). Otherwise it will be passed as it is.

check_peak_size#

dipy.viz.horizon.util.check_peak_size(pams, *, ref_img_shape=None, sync_imgs=False)[source]#

Check shape of peaks.

Parameters:
pamsPeaksAndMetrics

Peaks and metrics.

ref_img_shapetuple, optional

3D shape of the image, by default None.

sync_imgsbool, optional

True if the images are synchronized, by default False.

Returns:
bool

If the peaks are aligned with images and other peaks.

ClustersVisualizer#

class dipy.viz.horizon.visualizer.cluster.ClustersVisualizer(show_manager, scene, tractograms, *, enable_callbacks=True)[source]#

Bases: object

Attributes:
centroid_actors
cluster_actors
lengths
sizes
tractogram_clusters

Methods

add_cluster_actors

recluster_tractograms

add_cluster_actors(tract_idx, streamlines, thr, colors)[source]#
property centroid_actors#
property cluster_actors#
property lengths#
recluster_tractograms(thr)[source]#
property sizes#
property tractogram_clusters#

PeakActor#

class dipy.viz.horizon.visualizer.peak.PeakActor(directions, indices, *, values=None, affine=None, colors=None, lookup_colormap=None, linewidth=1, symmetric=True)[source]#

Bases: vtkActor

FURY actor for visualizing DWI peaks.

Parameters:
directionsndarray

Peak directions. The shape of the array should be (X, Y, Z, D, 3).

indicestuple

Indices given in tuple(x_indices, y_indices, z_indices) format for mapping 2D ODF array to 3D voxel grid.

valuesndarray, optional

Peak values. The shape of the array should be (X, Y, Z, D).

affinearray, optional

4x4 transformation array from native coordinates to world coordinates.

colorsNone or string (‘rgb_standard’) or tuple (3D or 4D) or array/ndarray (N, 3 or 4) or (K, 3 or 4) or (N, ) or (K, )

If None a standard orientation colormap is used for every line. If one tuple of color is used. Then all streamlines will have the same color. If an array (N, 3 or 4) is given, where N is equal to the number of points. Then every point is colored with a different RGB(A) color. If an array (K, 3 or 4) is given, where K is equal to the number of lines. Then every line is colored with a different RGB(A) color. If an array (N, ) is given, where N is the number of points then these are considered as the values to be used by the colormap. If an array (K,) is given, where K is the number of lines then these are considered as the values to be used by the colormap.

lookup_colormapvtkLookupTable, optional

Add a default lookup table to the colormap. Look at fury.actor.colormap_lookup_table() for more information.

linewidthfloat, optional

Line thickness.

symmetric: bool, optional

If True, peaks are drawn for both peaks_dirs and -peaks_dirs. Else, peaks are only drawn for directions given by peaks_dirs.

Attributes:
cross_section
global_opacity
high_ranges
is_range
linewidth
low_ranges
max_centers
min_centers

Methods

display_cross_section

display_extent

property cross_section#
display_cross_section(x, y, z)[source]#
display_extent(x1, x2, y1, y2, z1, z2)[source]#
property global_opacity#
property high_ranges#
property is_range#
property linewidth#
property low_ranges#
property max_centers#
property min_centers#

PeaksVisualizer#

class dipy.viz.horizon.visualizer.peak.PeaksVisualizer(pam, world_coords)[source]#

Bases: object

Attributes:
actors
property actors#

peak#

dipy.viz.horizon.visualizer.peak.peak(peaks_dirs, *, peaks_values=None, mask=None, affine=None, colors=None, linewidth=1, lookup_colormap=None, symmetric=True)[source]#

Visualize peak directions as given from peaks_from_model function.

Parameters:
peaks_dirsndarray

Peak directions. The shape of the array should be (X, Y, Z, D, 3).

peaks_valuesndarray, optional

Peak values. The shape of the array should be (X, Y, Z, D).

affinearray, optional

4x4 transformation array from native coordinates to world coordinates.

maskndarray, optional

3D mask

colorstuple or None, optional

Default None. If None then every peak gets an orientation color in similarity to a DEC map.

lookup_colormapvtkLookupTable, optional

Add a default lookup table to the colormap. Look at fury.actor.colormap_lookup_table() for more information.

linewidthfloat, optional

Line thickness. Default is 1.

symmetricbool, optional

If True, peaks are drawn for both peaks_dirs and -peaks_dirs. Else, peaks are only drawn for directions given by peaks_dirs. Default is True.

Returns:
peak_actorPeakActor

Actor or LODActor representing the peaks directions and/or magnitudes.

SlicesVisualizer#

class dipy.viz.horizon.visualizer.slice.SlicesVisualizer(interactor, scene, data, *, affine=None, world_coords=False, percentiles=(0, 100), rgb=False)[source]#

Bases: object

Attributes:
data_shape
intensities_range
rgb
selected_slices
slice_actors
volume_max
volume_min

Methods

change_volume

register_picker_callback

change_volume(prev_idx, next_idx, intensities, visible_slices)[source]#
property data_shape#
property intensities_range#
register_picker_callback(callback)[source]#
property rgb#
property selected_slices#
property slice_actors#
property volume_max#
property volume_min#

SurfaceVisualizer#

class dipy.viz.horizon.visualizer.surface.SurfaceVisualizer(surface, scene, color)[source]#

Bases: object

Attributes:
actors
property actors#

build_label#

dipy.viz.panel.build_label(text, *, font_size=18, bold=False)[source]#

Simple utility function to build labels

Parameters:
textstr
font_sizeint
boldbool
Returns:
labelTextBlock2D

slicer_panel#

dipy.viz.panel.slicer_panel(scene, iren, *, data=None, affine=None, world_coords=False, pam=None, mask=None, mem=None)[source]#

Slicer panel with slicer included

Parameters:
sceneScene

Scene.

irenInteractor

Interactor.

data3d ndarray

Data to be sliced.

affine4x4 ndarray

Affine matrix.

world_coordsbool

If True then the affine is applied.

peaksPeaksAndMetrics

Default None

mem
Returns:
panelPanel

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)[source]#

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)[source]#

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)[source]#

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

image_mosaic#

dipy.viz.plotting.image_mosaic(images, *, ax_labels=None, ax_kwargs=None, figsize=None, filename=None)[source]#

Draw a mosaic of 2D images using pyplot.imshow(). A colorbar is drawn beside each image.

Parameters:
images: list of ndarray

Images to render.

ax_labels: list of str, optional

Label for each image.

ax_kwargs: list of dictionaries, optional

keyword arguments passed to imshow for each image. One dictionary per image.

figsize: tuple of ints, optional

Figure size.

filename: str, optional

When given, figure is saved to disk under this name.

Returns:
fig: pyplot.Figure

The figure.

ax: pyplot.Axes or array of Axes

The subplots for each image.

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)[source]#

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.

vminfloat, optional

Minimum value to cut the z.

vmaxfloat, optional

Minimum value to cut the z.

cmapmatplotlib.colors.Colormap, optional

Colormap.

cbarbool, optional

Whether to add the color-bar to the figure.

tribool, optional

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

boundarybool, optional

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)[source]#

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)[source]#

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_kwargsdict

Extra parameters for saving figure, e.g. dpi=300.

draw_lattice_2d#

dipy.viz.regtools.draw_lattice_2d(nrows, ncols, delta)[source]#

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)[source]#

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_kwargsdict

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)[source]#

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_kwargsdict

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)[source]#

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='sagittal', colors=None, linewidth=0.3, save_as=None)[source]#

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: ‘sagittal’, ‘axial’ and ‘coronal’.

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)[source]#

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)[source]#

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)[source]#

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.