ants.viz package¶
Submodules¶
ants.viz.create_tiled_mosaic module¶
- ants.viz.create_tiled_mosaic.create_tiled_mosaic(image, rgb=None, mask=None, overlay=None, output=None, alpha=1.0, direction=0, pad_or_crop=None, slices=None, flip_slice=None, permute_axes=False)[source]¶
Create a tiled mosaic of 2D slice images from a 3D ANTsImage.
ANTsR function : N/A ANTs function : createTiledMosaic
- Parameters:
image (ANTsImage) – base image to visualize
rgb (ANTsImage) – optional overlay image to display on top of base image
mask (ANTsImage) – optional mask image
alpha (float) – alpha value for rgb/overlay image
direction (python:integer or string) – which axis to visualize options: 0, 1, 2, ‘x’, ‘y’, ‘z’
pad_or_crop (list of 2-tuples) –
padding or cropping values for each dimension and each side. - to crop the X dimension, use the following:
pad_or_crop = [(10,10), 0, 0]
- to pad the X dimension, use the following:
pad_or_crop = [(-10,-10), 0, 0]
slices (list/numpy.ndarray or python:integer or 3-tuple) –
- if list or numpy.ndarray:
slices to use
- if integer:
number of slices to incremenet
- if 3-tuple:
(# slices to increment, min slice, max slice)
flip_slice (2-tuple of boolean) – (whether to flip X direction, whether to flip Y direction)
permute_axes (boolean) – whether to permute axes
output (string) – output filename where mosaic image will be saved. If not given, this function will save to a temp file, then return the image as a PIL.Image object
ANTs –
---- –
-i, –input-image inputImageFilename -r, –rgb-image rgbImageFilename -x, –mask-image maskImageFilename -a, –alpha value -e, –functional-overlay [rgbImageFileName,maskImageFileName,<alpha=1>] -o, –output tiledMosaicImage -t, –tile-geometry RxC -d, –direction 0/1/2/x/y/(z) -p, –pad-or-crop padVoxelWidth
[padVoxelWidth,<constantValue=0>] [lowerPadding[0]xlowerPadding[1],upperPadding[0]xupperPadding[1],constantValue]
- -s, –slices Slice1xSlice2xSlice3…
numberOfSlicesToIncrement [numberOfSlicesToIncrement,<minSlice=0>,<maxSlice=lastSlice>]
-f, –flip-slice flipXxflipY -g, –permute-axes doPermute -h
-50 (CreateTiledMosaic -i OAS1_0457_MR1_mpr_n3_anon_sbj_111BrainSegmentation0N4 . nii . gz -r OAS1_0457_MR1_mpr_n3_anon_sbj_111CorticalThickness_hot . nii . gz -x OAS1_0457_MR1_mpr_n3_anon_sbj_111CorticalThickness_mask . nii . gz -o OAS1_0457_MR1_mpr_n3_anon_sbj_111_tiledMosaic . png -a 1.0 -t -1 x8 -d 2 -p [ -15x) –
-30 (-15x) –
[2 (0] -s) –
100 –
160] –
Example
>>> import ants >>> image = ants.image_read(ants.get_ants_data('ch2')) >>> plt = ants.create_tiled_mosaic(image)
ants.viz.plot module¶
Create a static 2D image of a 2D ANTsImage or a tile of slices from a 3D ANTsImage
TODO: - add plot_multichannel function for plotting multi-channel images
support for quivers as well
add plot_gif function for making a gif/video or 2D slices across a 3D image
- ants.viz.plot.movie(image, filename=None, writer=None, fps=30)[source]¶
Create and save a movie - mp4, gif, etc - of the various 2D slices of a 3D ants image
- Try this:
conda install -c conda-forge ffmpeg
Example
>>> import ants >>> mni = ants.image_read(ants.get_data('mni')) >>> ants.movie(mni, filename='~/desktop/movie.mp4')
- ants.viz.plot.plot(image, overlay=None, blend=False, alpha=1, cmap='Greys_r', overlay_cmap='turbo', overlay_alpha=0.9, vminol=None, vmaxol=None, cbar=False, cbar_length=0.8, cbar_dx=0.0, cbar_vertical=True, axis=0, nslices=12, slices=None, ncol=None, slice_buffer=None, black_bg=True, bg_thresh_quant=0.01, bg_val_quant=0.99, domain_image_map=None, crop=False, scale=False, reverse=False, title=None, title_fontsize=20, title_dx=0.0, title_dy=0.0, filename=None, dpi=500, figsize=1.5, reorient=True, resample=True)[source]¶
Plot an ANTsImage.
Use mask_image and/or threshold_image to preprocess images to be be overlaid and display the overlays in a given range. See the wiki examples.
By default, images will be reoriented to ‘LAI’ orientation before plotting. So, if axis == 0, the images will be ordered from the left side of the brain to the right side of the brain. If axis == 1, the images will be ordered from the anterior (front) of the brain to the posterior (back) of the brain. And if axis == 2, the images will be ordered from the inferior (bottom) of the brain to the superior (top) of the brain.
ANTsR function: plot.antsImage
- Parameters:
image (ANTsImage) – image to plot
overlay (ANTsImage) – image to overlay on base image
cmap (string) – colormap to use for base image. See matplotlib.
overlay_cmap (string) – colormap to use for overlay images, if applicable. See matplotlib.
overlay_alpha (float) – level of transparency for any overlays. Smaller value means the overlay is more transparent. See matplotlib.
axis (python:integer) – which axis to plot along if image is 3D
nslices (python:integer) – number of slices to plot if image is 3D
slices (list or tuple of python:integers) – specific slice indices to plot if image is 3D. If given, this will override nslices. This can be absolute array indices (e.g. (80,100,120)), or this can be relative array indices (e.g. (0.4,0.5,0.6))
ncol (python:integer) – Number of columns to have on the plot if image is 3D.
slice_buffer (python:integer) – how many slices to buffer when finding the non-zero slices of a 3D images. So, if slice_buffer = 10, then the first slice in a 3D image will be the first non-zero slice index plus 10 more slices.
black_bg (boolean) –
if True, the background of the image(s) will be black. if False, the background of the image(s) will be determined by the
values bg_thresh_quant and bg_val_quant.
bg_thresh_quant (float) –
if white_bg=True, the background will be determined by thresholding the image at the bg_thresh quantile value and setting the background intensity to the bg_val quantile value. This value should be in [0, 1] - somewhere around 0.01 is recommended.
equal to 1 will threshold the entire image
equal to 0 will threshold none of the image
bg_val_quant (float) –
if white_bg=True, the background will be determined by thresholding the image at the bg_thresh quantile value and setting the background intensity to the bg_val quantile value. This value should be in [0, 1]
equal to 1 is pure white
equal to 0 is pure black
somewhere in between is gray
domain_image_map (ANTsImage) – this input ANTsImage or list of ANTsImage types contains a reference image domain_image and optional reference mapping named domainMap. If supplied, the image(s) to be plotted will be mapped to the domain image space before plotting - useful for non-standard image orientations.
crop (boolean) – if true, the image(s) will be cropped to their bounding boxes, resulting in a potentially smaller image size. if false, the image(s) will not be cropped
scale (boolean or 2-tuple) – if true, nothing will happen to intensities of image(s) and overlay(s) if false, dynamic range will be maximized when visualizing overlays if 2-tuple, the image will be dynamically scaled between these quantiles
reverse (boolean) – if true, the order in which the slices are plotted will be reversed. This is useful if you want to plot from the front of the brain first to the back of the brain, or vice-versa
title (string) – add a title to the plot
filename (string) – if given, the resulting image will be saved to this file
dpi (python:integer) – determines resolution of image if saved to file. Higher values result in higher resolution images, but at a cost of having a larger file size
resample (bool) – if true, resample image if spacing is very unbalanced.
Example
>>> import ants >>> import numpy as np >>> img = ants.image_read(ants.get_data('r16')) >>> segs = img.kmeans_segmentation(k=3)['segmentation'] >>> ants.plot(img, segs*(segs==1), crop=True) >>> ants.plot(img, segs*(segs==1), crop=False) >>> mni = ants.image_read(ants.get_data('mni')) >>> segs = mni.kmeans_segmentation(k=3)['segmentation'] >>> ants.plot(mni, segs*(segs==1), crop=False)
- ants.viz.plot.plot_directory(directory, recursive=False, regex='*', save_prefix='', save_suffix='', axis=None, **kwargs)[source]¶
Create and save an ANTsPy plot for every image matching a given regular expression in a directory, optionally recursively. This is a good function for quick visualize exploration of all of images in a directory
ANTsR function: N/A
- Parameters:
directory (string) – directory in which to search for images and plot them
recursive (boolean) – If true, this function will search through all directories under the given directory recursively to make plots. If false, this function will only create plots for images in the given directory
regex (string) – regular expression used to filter out certain filenames or suffixes
save_prefix (string) – sub-string that will be appended to the beginning of all saved plot filenames. Default is to add nothing.
save_suffix (string) – sub-string that will be appended to the end of all saved plot filenames. Default is add nothing.
kwargs (keyword arguments) – any additional arguments to pass onto the ants.plot function. e.g. overlay, alpha, cmap, etc. See ants.plot for more options.
Example
>>> import ants >>> ants.plot_directory(directory='~/desktop/testdir', recursive=False, regex='*')
- ants.viz.plot.plot_grid(images, slices=None, axes=2, figsize=1.0, rpad=0, cpad=0, vmin=None, vmax=None, colorbar=True, cmap='Greys_r', title=None, tfontsize=20, title_dx=0, title_dy=0, rlabels=None, rfontsize=14, rfontcolor='white', rfacecolor='black', clabels=None, cfontsize=14, cfontcolor='white', cfacecolor='black', filename=None, dpi=400, transparent=True, **kwargs)[source]¶
Plot a collection of images in an arbitrarily-defined grid
Matplotlib named colors: https://matplotlib.org/examples/color/named_colors.html
- Parameters:
images (list of ANTsImage python:types) – image(s) to plot. if one image, this image will be used for all grid locations. if multiple images, they should be arrange in a list the same shape as the gridsize argument.
slices (python:integer or list of python:integers) – slice indices to plot if one integer, this slice index will be used for all images if multiple integers, they should be arranged in a list the same shape as the gridsize argument
axes (python:integer or list of python:integers) – axis or axes along which to plot image slices if one integer, this axis will be used for all images if multiple integers, they should be arranged in a list the same shape as the gridsize argument
Example
>>> import ants >>> import numpy as np >>> mni1 = ants.image_read(ants.get_data('mni')) >>> mni2 = mni1.smooth_image(1.) >>> mni3 = mni1.smooth_image(2.) >>> mni4 = mni1.smooth_image(3.) >>> images = np.asarray([[mni1, mni2], ... [mni3, mni4]]) >>> slices = np.asarray([[100, 100], ... [100, 100]]) >>> #axes = np.asarray([[2,2],[2,2]]) >>> # standard plotting >>> ants.plot_grid(images=images, slices=slices, title='2x2 Grid') >>> ants.plot_grid(images.reshape(1,4), slices.reshape(1,4), title='1x4 Grid') >>> ants.plot_grid(images.reshape(4,1), slices.reshape(4,1), title='4x1 Grid')
>>> # Padding between rows and/or columns >>> ants.plot_grid(images, slices, cpad=0.02, title='Col Padding') >>> ants.plot_grid(images, slices, rpad=0.02, title='Row Padding') >>> ants.plot_grid(images, slices, rpad=0.02, cpad=0.02, title='Row and Col Padding')
>>> # Adding plain row and/or column labels >>> ants.plot_grid(images, slices, title='Adding Row Labels', rlabels=['Row #1', 'Row #2']) >>> ants.plot_grid(images, slices, title='Adding Col Labels', clabels=['Col #1', 'Col #2']) >>> ants.plot_grid(images, slices, title='Row and Col Labels', rlabels=['Row 1', 'Row 2'], clabels=['Col 1', 'Col 2'])
>>> # Making a publication-quality image >>> images = np.asarray([[mni1, mni2, mni2], ... [mni3, mni4, mni4]]) >>> slices = np.asarray([[100, 100, 100], ... [100, 100, 100]]) >>> axes = np.asarray([[0, 1, 2], [0, 1, 2]]) >>> ants.plot_grid(images, slices, axes, title='Publication Figures with ANTsPy', tfontsize=20, title_dy=0.03, title_dx=-0.04, rlabels=['Row 1', 'Row 2'], clabels=['Col 1', 'Col 2', 'Col 3'], rfontsize=16, cfontsize=16)
- ants.viz.plot.plot_hist(image, threshold=0.0, fit_line=False, normfreq=True, title=None, grid=True, xlabel=None, ylabel=None, facecolor='green', alpha=0.75)[source]¶
Plot a histogram from an ANTsImage
- Parameters:
image (ANTsImage) – image from which histogram will be created
- ants.viz.plot.plot_ortho(image, overlay=None, reorient=True, blend=False, xyz=None, xyz_lines=True, xyz_color='red', xyz_alpha=0.6, xyz_linewidth=2, xyz_pad=5, orient_labels=True, alpha=1, cmap='Greys_r', overlay_cmap='jet', overlay_alpha=0.9, black_bg=True, bg_thresh_quant=0.01, bg_val_quant=0.99, crop=False, scale=False, domain_image_map=None, title=None, titlefontsize=24, title_dx=0, title_dy=0, text=None, textfontsize=24, textfontcolor='white', text_dx=0, text_dy=0, filename=None, dpi=500, figsize=1.0, flat=False, transparent=True, resample=False)[source]¶
Plot an orthographic view of a 3D image
Use mask_image and/or threshold_image to preprocess images to be be overlaid and display the overlays in a given range. See the wiki examples.
- TODO:
add colorbar option
ANTsR function: N/A
- imageANTsImage
image to plot
- overlayANTsImage
image to overlay on base image
- sliceslist or tuple of 3 integers
slice indices along each axis to plot This can be absolute array indices (e.g. (80,100,120)), or this can be relative array indices (e.g. (0.4,0.5,0.6)). The default is to take the middle slice along each axis.
- xyzlist or tuple of 3 integers
if given, solid lines will be drawn to converge at this coordinate. This is useful for pinpointing a specific location in the image.
- flatboolean
if true, the ortho image will be plot in one row if false, the ortho image will be a 2x2 grid with the bottom
left corner blank
- cmapstring
colormap to use for base image. See matplotlib.
- overlay_cmapstring
colormap to use for overlay images, if applicable. See matplotlib.
- overlay_alphafloat
level of transparency for any overlays. Smaller value means the overlay is more transparent. See matplotlib.
- axisinteger
which axis to plot along if image is 3D
- black_bgboolean
if True, the background of the image(s) will be black. if False, the background of the image(s) will be determined by the
values bg_thresh_quant and bg_val_quant.
- bg_thresh_quantfloat
if white_bg=True, the background will be determined by thresholding the image at the bg_thresh quantile value and setting the background intensity to the bg_val quantile value. This value should be in [0, 1] - somewhere around 0.01 is recommended.
equal to 1 will threshold the entire image
equal to 0 will threshold none of the image
- bg_val_quantfloat
if white_bg=True, the background will be determined by thresholding the image at the bg_thresh quantile value and setting the background intensity to the bg_val quantile value. This value should be in [0, 1]
equal to 1 is pure white
equal to 0 is pure black
somewhere in between is gray
- domain_image_mapANTsImage
this input ANTsImage or list of ANTsImage types contains a reference image domain_image and optional reference mapping named domainMap. If supplied, the image(s) to be plotted will be mapped to the domain image space before plotting - useful for non-standard image orientations.
- cropboolean
if true, the image(s) will be cropped to their bounding boxes, resulting in a potentially smaller image size. if false, the image(s) will not be cropped
- scaleboolean or 2-tuple
if true, nothing will happen to intensities of image(s) and overlay(s) if false, dynamic range will be maximized when visualizing overlays if 2-tuple, the image will be dynamically scaled between these quantiles
- titlestring
add a title to the plot
- filenamestring
if given, the resulting image will be saved to this file
- dpiinteger
determines resolution of image if saved to file. Higher values result in higher resolution images, but at a cost of having a larger file size
resample : resample image in case of unbalanced spacing
>>> import ants >>> mni = ants.image_read(ants.get_data('mni')) >>> ants.plot_ortho(mni, xyz=(100,100,100)) >>> mni2 = mni.threshold_image(7000, mni.max()) >>> ants.plot_ortho(mni, overlay=mni2) >>> ants.plot_ortho(mni, overlay=mni2, flat=True) >>> ants.plot_ortho(mni, overlay=mni2, xyz=(110,110,110), xyz_lines=False, text='Lines Turned Off', textfontsize=22) >>> ants.plot_ortho(mni, mni2, xyz=(120,100,100), text=' Example
- Ortho Text’, textfontsize=26,
title=’Example Ortho Title’, titlefontsize=26)
- ants.viz.plot.plot_ortho_double(image, image2, overlay=None, overlay2=None, reorient=True, xyz=None, xyz_lines=True, xyz_color='red', xyz_alpha=0.6, xyz_linewidth=2, xyz_pad=5, cmap='Greys_r', alpha=1, cmap2='Greys_r', alpha2=1, overlay_cmap='jet', overlay_alpha=0.9, overlay_cmap2='jet', overlay_alpha2=0.9, black_bg=True, bg_thresh_quant=0.01, bg_val_quant=0.99, crop=False, scale=False, crop2=False, scale2=True, domain_image_map=None, title=None, titlefontsize=24, title_dx=0, title_dy=0, text=None, textfontsize=24, textfontcolor='white', text_dx=0, text_dy=0, filename=None, dpi=500, figsize=1.0, flat=True, transpose=False, transparent=True)[source]¶
Create a pair of orthographic plots with overlays.
Use mask_image and/or threshold_image to preprocess images to be be overlaid and display the overlays in a given range. See the wiki examples.
Example
>>> import ants >>> mni = ants.image_read(ants.get_data('mni')) >>> ch2 = ants.image_read(ants.get_data('ch2')) >>> ants.plot_ortho_double(mni, ch2)
- ants.viz.plot.plot_ortho_stack(images, overlays=None, reorient=True, xyz=None, xyz_lines=False, xyz_color='red', xyz_alpha=0.6, xyz_linewidth=2, xyz_pad=5, cmap='Greys_r', alpha=1, overlay_cmap='jet', overlay_alpha=0.9, black_bg=True, bg_thresh_quant=0.01, bg_val_quant=0.99, crop=False, scale=False, domain_image_map=None, title=None, titlefontsize=24, title_dx=0, title_dy=0, text=None, textfontsize=24, textfontcolor='white', text_dx=0, text_dy=0, filename=None, dpi=500, figsize=1.0, colpad=0, rowpad=0, transpose=False, transparent=True, orient_labels=True)[source]¶
Create a stack of orthographic plots with optional overlays.
Use mask_image and/or threshold_image to preprocess images to be be overlaid and display the overlays in a given range. See the wiki examples.
Example
>>> import ants >>> mni = ants.image_read(ants.get_data('mni')) >>> ch2 = ants.image_read(ants.get_data('ch2')) >>> ants.plot_ortho_stack([mni,mni,mni])
ants.viz.render_surface_function module¶
- ants.viz.render_surface_function.render_surface_function(surfimg, funcimg=None, alphasurf=0.2, alphafunc=1.0, isosurf=0.5, isofunc=0.5, smoothsurf=None, smoothfunc=None, cmapsurf='grey', cmapfunc='red', filename=None, notebook=False, auto_open=False)[source]¶
Render an image as a base surface and an optional collection of other image.
- ANTsR function: renderSurfaceFunction
NOTE: The ANTsPy version of this function is actually completely different than the ANTsR version, although they should produce similar results.
- Parameters:
surfimg (ANTsImage) – Input image to use as rendering substrate.
funcimg (ANTsImage) – Input list of images to use as functional overlays.
alphasurf (scalar) – alpha for the surface contour
alphafunc (scalar) – alpha value for functional blobs
isosurf (scalar) – intensity level that defines lower threshold for surface image
isofunc (scalar) – intensity level that defines lower threshold for functional image
smoothsurf (scalar (optional)) – smoothing for the surface image
smoothfunc (scalar (optional)) – smoothing for the functional image
cmapsurf (string) – color map for surface image
cmapfunc (string) – color map for functional image
filename (string) – where to save rendering. if None, will plot interactively
notebook (boolean) – whether you’re in a jupyter notebook.
- Return type:
N/A
Example
>>> import ants >>> mni = ants.image_read(ants.get_ants_data('mni')) >>> mnia = ants.image_read(ants.get_ants_data('mnia')) >>> ants.render_surface_function(mni, mnia, alphasurf=0.1, filename='/users/ncullen/desktop/surffnc.png')
ants.viz.surface module¶
- ants.viz.surface.get_canonical_views()[source]¶
Get the canonical views used for surface and volume rendering. You can use this as a reference for slightly altering rotation parameters in ants.surf and ants.vol functions.
Note that these views are for images that have ‘RPI’ orientation. Images are automatically reoriented to RPI in ANTs surface and volume rendering functions but you can reorient images yourself with `img.reorient_image2(‘RPI’)
- ants.viz.surface.surf(x, y=None, z=None, quantlimits=(0.1, 0.9), colormap='jet', grayscale=0.7, bg_grayscale=0.9, alpha=None, inflation_factor=0, tol=0.03, smoothing_sigma=0.0, rotation_params=(90, 0, 270), overlay_limits=None, filename=None, verbose=False)[source]¶
Render a function onto a surface.
- ANTsR function: antsrSurf
NOTE: the ANTsPy version of this function does NOT make a function call to ANTs, unlike the ANTsR version, so you don’t have to worry about paths.
- Parameters:
x (ANTsImage) – input image defining the surface on which to render
y (ANTsImage) – input image list defining the function to render on the surface. these image(s) should be in the same space as x.
z (ANTsImage) – input image list mask for each y function to render on the surface. these image(s) should be in the same space as y.
quantlimits (tuple/list) – lower and upper quantile limits for overlay
colormap (string) – one of: grey, red, green, blue, copper, jet, hsv, spring, summer, autumn, winter, hot, cool, overunder, custom
alpha (scalar) – transparency vector for underlay and each overlay, default zero
inflation_factor (python:integer) – number of inflation iterations to run
tol (float) – error tolerance for surface reconstruction. Smaller values will lead to better surfaces, at the cost of taking longer. Try decreasing this value if your surfaces look very block-y.
smoothing_sigma (scalar) – gaussian smooth the overlay by this sigma
rotation_params (tuple/list/ndarray) – 3 Rotation angles expressed in degrees or a matrix of rotation parameters that will be applied in sequence.
overlay_limits (tuple (optional)) – absolute lower and upper limits for functional overlay. this parameter will override quantlimits. Currently, this will set levels above overlayLimits[2] to overlayLimits[1]. Can be a list of length of y.
filename (string) – prefix filename for output pngs
verbose (boolean) – prints the command used to call antsSurf
- Return type:
N/A
Example
>>> import ants >>> ch2i = ants.image_read( ants.get_ants_data("ch2") ) >>> ch2seg = ants.threshold_image( ch2i, "Otsu", 3 ) >>> wm = ants.threshold_image( ch2seg, 3, 3 ) >>> wm2 = wm.smooth_image( 1 ).threshold_image( 0.5, 1e15 ) >>> kimg = ants.weingarten_image_curvature( ch2i, 1.5 ).smooth_image( 1 ) >>> wmz = wm2.iMath("MD",3) >>> rp = [(90,180,90), (90,180,270), (90,180,180)] >>> ants.surf( x=wm2, y=[kimg], z=[wmz], inflation_factor=255, overlay_limits=(-0.3,0.3), verbose = True, rotation_params = rp, filename='/users/ncullen/desktop/surface.png')
- ants.viz.surface.surf_fold(image, outfile, dilation=0, inflation=10, alpha=1.0, overlay=None, overlay_mask=None, overlay_cmap='jet', overlay_scale=False, overlay_alpha=1.0, rotation=None, cut_idx=None, cut_side='left', grayscale=0.7, bg_grayscale=0.9, verbose=False, cleanup=True)[source]¶
Generate a cortical folding surface of the gray matter of a brain image.
- rotation3-tuple | string | 2-tuple of string & 3-tuple
if 3-tuple, this will be the rotation from RPI about x-y-z axis if string, this should be a canonical view (see : ants.get_canonical_views()) if 2-tuple, the first value should be a string canonical view, and the second
value should be a 3-tuple representing a delta change in each axis from the canonical view (useful for apply slight changes to canonical views)
- NOTE:
- rotation=(0,0,0) will be a view of the top of the brain with the
front of the brain facing the bottom of the image
- NOTE:
- 1st valuecontrols rotation about x axis (anterior/posterior tilt)
note : the x axis extends to the side of you
- 2nd valuecontrols rotation about y axis (inferior/superior tilt)
note : the y axis extends in front and behind you
- 3rd valuecontrols rotation about z axis (left/right tilt)
note : thte z axis extends up and down
Example
>>> import ants >>> mni = ants.image_read(ants.get_data('mni')) >>> seg = mni.otsu_segmentation(k=3) >>> wm_img = seg.threshold_image(3,3) >>> ants.surf_fold(wm_img, outfile='~/desktop/surf_fold.png') >>> # with overlay >>> overlay = ants.weingarten_image_curvature( mni, 1.5 ).smooth_image( 1 ) >>> ants.surf_fold(image=wm_img, overlay=overlay, outfile='~/desktop/surf_fold2.png')
- ants.viz.surface.surf_smooth(image, outfile, dilation=1.0, smooth=1.0, threshold=0.5, inflation=200, alpha=1.0, cut_idx=None, cut_side='left', overlay=None, overlay_mask=None, overlay_cmap='jet', overlay_scale=False, overlay_alpha=1.0, rotation=None, grayscale=0.7, bg_grayscale=0.9, verbose=False, cleanup=True)[source]¶
Generate a cortical folding surface of the gray matter of a brain image.
- rotation3-tuple | string | 2-tuple of string & 3-tuple
if 3-tuple, this will be the rotation from RPI about x-y-z axis if string, this should be a canonical view (see : ants.get_canonical_views()) if 2-tuple, the first value should be a string canonical view, and the second
value should be a 3-tuple representing a delta change in each axis from the canonical view (useful for apply slight changes to canonical views)
- NOTE:
- rotation=(0,0,0) will be a view of the top of the brain with the
front of the brain facing the bottom of the image
- NOTE:
- 1st valuecontrols rotation about x axis (anterior/posterior tilt)
note : the x axis extends to the side of you
- 2nd valuecontrols rotation about y axis (inferior/superior tilt)
note : the y axis extends in front and behind you
- 3rd valuecontrols rotation about z axis (left/right tilt)
note : thte z axis extends up and down
Example
>>> import ants >>> mni = ants.image_read(ants.get_data('mni')) >>> seg = mni.otsu_segmentation(k=3) >>> wm_img = seg.threshold_image(3,3) >>> ants.surf_fold(wm_img, outfile='~/desktop/surf_fold.png') >>> # with overlay >>> overlay = ants.weingarten_image_curvature( mni, 1.5 ).smooth_image( 1 ) >>> ants.surf_fold(image=wm_img, overlay=overlay, outfile='~/desktop/surf_fold2.png')
ants.viz.volume module¶
- ants.viz.volume.vol(volume, overlays=None, quantlimits=(0.1, 0.9), colormap='jet', rotation_params=(90, 0, 270), overlay_limits=None, magnification_factor=1.0, intensity_truncation=(0.0, 1.0), filename=None, verbose=False)[source]¶
Render an ANTsImage as a volume with optional ANTsImage functional overlay. This function is beautiful, and runs very fast. It requires VTK.
- ANTsR function: antsrVol
NOTE: the ANTsPy version of this function does NOT make a function call to ANTs, unlike the ANTsR version, so you don’t have to worry about paths.
- Parameters:
volume (ANTsImage) – base volume to render
overlay (list of ANTsImages) – functional overlay to render on the volume image. These images should be in the same space
colormap (string) –
- possible values:
grey, red, green, blue, copper, jet, hsv, spring, summer, autumn, winter, hot, cool, overunder, custom
rotation_params (tuple or collection of tuples or np.ndarray w/ shape (N,3)) –
rotation parameters to render. The final image will be a stitch of each image from the given rotation params. e.g. if rotation_params = [(90,90,90),(180,180,180)], then the final
stiched image will have 2 brain renderings at those angles
overlay_limts –
magnification_factor (float) – how much to zoom in on the image before rendering. If the stitched images are too far apart, try increasing this value. If the brain volume gets cut off in the image, try decreasing this value
intensity_truncation (2-tuple of float) – percentile to truncate intensity of overlay
filename (string) – final filename to which the final rendered volume stitch image will be saved this will always be a .png file
verbose (boolean) – whether to print updates during rendering
- Returns:
- a numpy array representing the final stitched image.
Effects
——-
- saves a few png files to disk
Example
>>> import ants >>> ch2i = ants.image_read( ants.get_ants_data("mni") ) >>> ch2seg = ants.threshold_image( ch2i, "Otsu", 3 ) >>> wm = ants.threshold_image( ch2seg, 2, 2 ) >>> kimg = ants.weingarten_image_curvature( ch2i, 1.5 ).smooth_image( 1 ) >>> rp = [(90,180,90), (90,180,270), (90,180,180)] >>> result = ants.vol( wm, [kimg], quantlimits=(0.01,0.99), filename='/users/ncullen/desktop/voltest.png')
- ants.viz.volume.vol_fold(image, outfile, magnification=1.0, dilation=0, inflation=10, alpha=1.0, overlay=None, overlay_mask=None, overlay_cmap='jet', overlay_scale=False, overlay_alpha=1.0, rotation=None, cut_idx=None, cut_side='left', grayscale=0.7, bg_grayscale=0.9, verbose=False, cleanup=True)[source]¶
Generate a cortical folding volume of the gray matter of a brain image.
- rotation3-tuple | string | 2-tuple of string & 3-tuple
if 3-tuple, this will be the rotation from RPI about x-y-z axis if string, this should be a canonical view (see : ants.get_canonical_views()) if 2-tuple, the first value should be a string canonical view, and the second
value should be a 3-tuple representing a delta change in each axis from the canonical view (useful for apply slight changes to canonical views)
- NOTE:
- rotation=(0,0,0) will be a view of the top of the brain with the
front of the brain facing the bottom of the image
- NOTE:
- 1st valuecontrols rotation about x axis (anterior/posterior tilt)
note : the x axis extends to the side of you
- 2nd valuecontrols rotation about y axis (inferior/superior tilt)
note : the y axis extends in front and behind you
- 3rd valuecontrols rotation about z axis (left/right tilt)
note : thte z axis extends up and down
Example
>>> import ants >>> ch2i = ants.image_read( ants.get_ants_data("mni") ) >>> ch2seg = ants.threshold_image( ch2i, "Otsu", 3 ) >>> wm = ants.threshold_image( ch2seg, 2, 2 ) >>> kimg = ants.weingarten_image_curvature( ch2i, 1.5 ).smooth_image( 1 ) >>> rp = [(90,180,90), (90,180,270), (90,180,180)] >>> result = ants.vol_fold( wm, overlay=kimg, outfile='/users/ncullen/desktop/voltest.png')