AFQ.utils.volume#

Attributes#

Functions#

_signed_distance(mask, max_tol)

Compute the signed distance transform of a binary mask, with a maximum

_betti(mask)

Calculate Betti numbers

transform_roi(roi, mapping, is_boolean[, max_tol, ...])

After being non-linearly transformed, ROIs can have holes in them,

density_map(tractogram[, n_sls, normalize])

Create a streamline density map.

dice_coeff(arr1, arr2[, weighted])

Compute Dice's coefficient between two images.

Module Contents#

AFQ.utils.volume.logger[source]#
AFQ.utils.volume._signed_distance(mask, max_tol)[source]#

Compute the signed distance transform of a binary mask, with a maximum tolerance for the distance values. This allows us to only have to calculated edt in a bounding box, which is faster.

AFQ.utils.volume._betti(mask)[source]#

Calculate Betti numbers

AFQ.utils.volume.transform_roi(roi, mapping, is_boolean, max_tol=3.0, return_tol=False)[source]#

After being non-linearly transformed, ROIs can have holes in them, or even disappear entirely, depending on the mapping, domain, and codomain. This method gives transformed ROIs that preserve, as close as possible, the topology of the original ROI: its number of connected components, the tunnels through it, and the cavities inside it. Specifically, using Betti numbers. Holes are repaired by dilating the warped ROI, up to a maximum tolerance. When the topology can be preserved, it will be preserved with minimal dilation.

Parameters:
roiNifti1Image, str, ndarray

The ROI to transform. Can be a path or image, which will be converted to an ndarray.

mappingDiffeomorphicMap object

A mapping between DWI space and a template.

is_booleanbool

Whether the ROI is boolean or not.

max_tolfloat, optional

Maximum tolerance for the signed distance field used to warp boolean masks. Default: 3.0

return_tolbool, optional

Whether to return the tolerance used to warp the boolean mask. If is_boolean is False, this parameter is ignored. Default: False

Returns:
The transformed ROI, as a Nifti1Image.
AFQ.utils.volume.density_map(tractogram, n_sls=None, normalize=False)[source]#

Create a streamline density map. based on: https://dipy.org/documentation/1.1.1./examples_built/streamline_formats/

Parameters:
tractogramStatefulTractogram

Stateful tractogram whose streamlines are used to make the density map.

n_slsint or None, optional

n_sls to randomly select to make the density map. If None, all streamlines are used. Default: None

normalizebool, optional

Whether to normalize maximum values to 1. Default: False

Returns:
Nifti1Image containing the density map.
AFQ.utils.volume.dice_coeff(arr1, arr2, weighted=True)[source]#

Compute Dice’s coefficient between two images.

Parameters:
arr1Nifti1Image, str, ndarray

One ndarray to compare. Can be a path or image, which will be converted to an ndarray.

arr2Nifti1Image, str, ndarray

The other ndarray to compare. Can be a path or image, which will be converted to an ndarray.

weightedbool, optional

Whether or not to weight the DICE coefficient as in [Cousineau2017]. The weighted Dice coefficient is calculated by adding the sum of all values in arr1 where arr2 is nonzero to the sum of all values in arr2 where arr1 is nonzero, then dividing that by the sum of all values in arr1 and arr2. Default: True

Returns:
The dice similarity between the images.

Notes

[Cousineau2017]

Cousineau M, Jodoin PM, Morency FC, et al. A test-retest study on Parkinson’s PPMI dataset yields statistically significant white matter fascicles. Neuroimage Clin. 2017;16:222-233. Published 2017 Jul 25. doi:10.1016/j.nicl.2017.07.020