mindboggle.thirdparty package¶
Submodules¶
mindboggle.thirdparty.FreeSurferColorLUT module¶
Copy of freesurfer/FreeSurferColorLUT.txt file.
-
lut_text
()¶
mindboggle.thirdparty.ants module¶
Functions that call ANTs (UPenn’s PICSL group) commands.
Mindboggle functions call the following ANTs functions
ImageMath:
'PropagateLabelsThroughMask' option in PropagateLabelsThroughMask()
if modify_surface_labels set to True:
PropagateLabelsThroughMask() called and '+' option in mindboggle
ThresholdImage:
PropagateLabelsThroughMask()
antsApplyTransformsToPoints:
write_shape_stats(), write_vertex_measures() in mindboggle
- Authors:
- Arno Klein, 2012-2016 (arno@mindboggle.info) http://binarybottle.com
Copyright 2016, Mindboggle team (http://mindboggle.info), Apache v2.0 License
-
ImageMath
(volume1, volume2, operator='m', output_file='')¶ Use the ImageMath function in ANTs to perform operation on two volumes:
m : Multiply --- use vm for vector multiply + : Add --- use v+ for vector add - : Subtract --- use v- for vector subtract / : Divide ^ : Power exp : Take exponent exp(imagevalue*value) addtozero : add image-b to image-a only over points where image-a has zero values overadd : replace image-a pixel with image-b pixel if image-b pixel is non-zero abs : absolute value total : Sums up values in an image or in image1*image2 (img2 is the probability mask) mean : Average of values in an image or in image1*image2 (img2 is the probability mask) vtotal : Sums up volumetrically weighted values in an image or in image1*image2 (img2 is the probability mask) Decision : Computes result=1./(1.+exp(-1.0*( pix1-0.25)/pix2)) Neg : Produce image negative
Parameters: - volume1 (string) – nibabel-readable image volume
- volume2 (string) – nibabel-readable image volume
- operator (string) – ImageMath string corresponding to mathematical operator
- output_file (string) – nibabel-readable image volume
Returns: output_file – name of output nibabel-readable image volume
Return type: string
Examples
>>> # Mask head with brain mask: >>> import os >>> from mindboggle.thirdparty.ants import ImageMath >>> from mindboggle.mio.fetch_data import prep_tests >>> urls, fetch_data = prep_tests() >>> volume1 = fetch_data(urls['T1_001'], '', '.nii.gz') >>> volume2 = fetch_data(urls['ants_mask'], '', '.nii.gz') >>> operator = 'm' >>> output_file = '' >>> output_file = ImageMath(volume1, volume2, operator, output_file) # doctest: +SKIP
View result (skip test):
>>> from mindboggle.mio.plots import plot_volumes >>> plot_volumes(output_file) # doctest: +SKIP
-
PropagateLabelsThroughMask
(mask, labels, mask_index=None, output_file='', binarize=True, stopvalue='')¶ Use ANTs to fill a binary volume mask with initial labels.
This program uses ThresholdImage and the ImageMath PropagateLabelsThroughMask functions in ANTs.
- ThresholdImage ImageDimension ImageIn.ext outImage.ext
- threshlo threshhi <insideValue> <outsideValue>
- PropagateLabelsThroughMask: Final output is the propagated label image.
- ImageMath ImageDimension Out.ext PropagateLabelsThroughMask speed/binaryimagemask.nii.gz initiallabelimage.nii.gz …
Parameters: - mask (string) – nibabel-readable image volume
- labels (string) – nibabel-readable image volume with integer labels
- mask_index (integer (optional)) – mask with just voxels having this value
- output_file (string (optional)) – nibabel-readable labeled image volume
- binarize (bool (optional)) – binarize mask?
- stopvalue (integer (optional)) – stopping value
Returns: output_file – name of labeled output nibabel-readable image volume
Return type: string
Examples
>>> # Propagate FreeSurfer labels through brain mask: >>> import os >>> from mindboggle.thirdparty.ants import PropagateLabelsThroughMask >>> from mindboggle.mio.fetch_data import prep_tests >>> urls, fetch_data = prep_tests() >>> labels = fetch_data(urls['freesurfer_labels'], '', '.nii.gz') >>> mask = fetch_data(urls['ants_mask'], '', '.nii.gz') >>> mask_index = None >>> output_file = '' >>> binarize = True >>> stopvalue = None >>> output_file = PropagateLabelsThroughMask(mask, labels, mask_index, ... output_file, binarize, stopvalue) # doctest: +SKIP
View result (skip test):
>>> from mindboggle.mio.plots import plot_volumes >>> plot_volumes(output_file) # doctest: +SKIP
-
ResampleImageBySpacing
(volume, output_file='', outxspc=1, outyspc=1, outzspc=1, dosmooth=0, addvox=0, nninterp=1)¶ Use the ResampleImageBySpacing function in ANTs to resample image volume.
- Usage: ResampleImageBySpacing ImageDimension ImageIn.ext outImage.ex
- outxspc outyspc <outzspc> <dosmooth?> <addvox> <nninterp?>
Parameters: - volume (string) – nibabel-readable image volume
- output_file (string) – nibabel-readable image volume
- outxspc (integer) – output x-spacing
- outyspc (integer) – output y-spacing
- outzspc (integer) – output z-spacing
- dosmooth (bool) – smooth?
- addvox (integer) – pad each dimension by addvox
- nninterp (bool) – nearest-neighbor interpolation?
Returns: output_file – name of output nibabel-readable image volume
Return type: string
Examples
>>> # Resample image so that 1mm voxels are 0.5mm voxels: >>> import os >>> from mindboggle.thirdparty.ants import ResampleImageBySpacing >>> from mindboggle.mio.fetch_data import prep_tests >>> urls, fetch_data = prep_tests() >>> volume = fetch_data(urls['T1_001'], '', '.nii.gz') >>> os.rename(volume, volume + '.nii.gz') >>> volume += '.nii.gz' >>> output_file = '' >>> outxspc = 1/2.0 >>> outyspc = 1/2.0 >>> outzspc = 1/2.0 >>> dosmooth = 0 >>> addvox = 0 >>> nninterp = 1 >>> output_file = ResampleImageBySpacing(volume, output_file, outxspc, ... outxspc, outzspc, dosmooth, addvox, nninterp) # doctest: +SKIP
View result (skip test):
>>> from mindboggle.mio.plots import plot_volumes >>> plot_volumes(output_file) # doctest: +SKIP
-
ThresholdImage
(volume, output_file='', threshlo=1, threshhi=10000)¶ Use the ThresholdImage function in ANTs to threshold image volume.
- Usage: ThresholdImage ImageDimension ImageIn.ext outImage.ext
- threshlo threshhi <insideValue> <outsideValue>
Parameters: - volume (string) – nibabel-readable image volume
- output_file (string) – nibabel-readable image volume
- threshlo (integer) – lower threshold
- threshhi (integer) – upper threshold
Returns: output_file – name of output nibabel-readable image volume
Return type: string
Examples
>>> import os >>> from mindboggle.thirdparty.ants import ThresholdImage >>> from mindboggle.mio.fetch_data import prep_tests >>> urls, fetch_data = prep_tests() >>> volume = fetch_data(urls['T1_001'], '', '.nii.gz') >>> os.rename(volume, volume + '.nii.gz') >>> volume += '.nii.gz' >>> output_file = '' >>> threshlo = 500 >>> threshhi = 10000 >>> output_file = ThresholdImage(volume, output_file, threshlo, threshhi) # doctest: +SKIP
View result (skip test):
>>> from mindboggle.mio.plots import plot_volumes >>> plot_volumes(output_file) # doctest: +SKIP
-
antsApplyTransformsToPoints
(points, transform_files, inverse_booleans=[0])¶ Run ANTs antsApplyTransformsToPoints function to transform points. (Creates pre- and post-transformed .csv points files for ANTs.)
Parameters: - points (list of lists of three integers) – point coordinate data
- transform_files (list) – transform file names
- inverse_booleans (list) – for each transform, one to apply inverse of transform (otherwise zero)
Returns: transformed_points – transformed point coordinate data
Return type: list of lists of three integers
Examples
>>> import numpy as np >>> from mindboggle.thirdparty.ants import antsApplyTransformsToPoints >>> from mindboggle.mio.vtks import read_points >>> from mindboggle.mio.fetch_data import prep_tests >>> urls, fetch_data = prep_tests() >>> xfm1 = fetch_data(urls['ants_affine_template2subject'], '', '.mat') >>> xfm2 = fetch_data(urls['ants_warp_template2subject'], '', '.nii.gz') >>> xfm3 = fetch_data(urls['OASIS-30_Atropos_template_to_MNI152_affine'], '', '.txt') >>> transform_files = [xfm1, xfm2, xfm3] >>> vtk_file = fetch_data(urls['left_pial'], '', '.vtk') >>> points = read_points(vtk_file) >>> inverse_booleans = [0,0,1] >>> transformed_points = antsApplyTransformsToPoints(points, ... transform_files, inverse_booleans) # doctest: +SKIP >>> print(np.array_str(np.array(transformed_points[0:5]), ... precision=5, suppress_small=True)) # doctest: +SKIP [[-11.23189 -46.78223 -39.88869] [-11.71384 -46.87075 -40.13328] [-12.56237 -46.99126 -40.04564] [ -9.66693 -46.0446 -41.36334] [-10.67998 -46.45458 -40.7572 ]]