ants.math.get_neighborhood
Functions
|
Get a hypercube neighborhood at a voxel. |
|
Get neighborhoods for voxels within mask. |
- get_neighborhood_at_voxel(image, center, kernel, physical_coordinates=False)[source]
Get a hypercube neighborhood at a voxel. Get the values in a local neighborhood of an image.
ANTsR function: getNeighborhoodAtVoxel
- Parameters:
image (
ants.core.ANTsImage) – image to get values from.center (
tuple/list) – indices for neighborhood centerkernel (
tuple/list) – either a collection of values for neighborhood radius (in voxels) or a binary collection of the same dimension as the image, specifying the shape of the neighborhood to extractphysical_coordinates (
bool) – whether voxel indices and offsets should be in voxel or physical coordinates
- Returns:
- valuesndarray
array of neighborhood values at the voxel
- indicesndarray
matrix providing the coordinates for each value
- Return type:
dictionary w/ following key-value pairs
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> center = (2,2) >>> radius = (3,3) >>> retval = ants.get_neighborhood_at_voxel(img, center, radius)
- get_neighborhood_in_mask(image, mask, radius, physical_coordinates=False, boundary_condition=None, spatial_info=False, get_gradient=False)[source]
Get neighborhoods for voxels within mask.
This converts a scalar image to a matrix with rows that contain neighbors around a center voxel
ANTsR function: getNeighborhoodInMask
- Parameters:
image (
ants.core.ANTsImage) – image to get values frommask (
ants.core.ANTsImage) – image indicating which voxels to examine. Each voxel > 0 will be used as the center of a neighborhoodradius (
tuple/list) – array of values for neighborhood radius (in voxels)physical_coordinates (
bool) – whether voxel indices and offsets should be in voxel or physical coordinatesboundary_condition (
string (optional)) –- how to handle voxels in a neighborhood, but not in the mask.
None : fill values with NaN image : use image value, even if not in mask mean : use mean of all non-NaN values for that neighborhood
spatial_info (
bool) – whether voxel locations and neighborhood offsets should be returned along with pixel values.get_gradient (
bool) – whether a matrix of gradients (at the center voxel) should be returned in addition to the value matrix (WIP)
- Returns:
if spatial_info is False–- if get_gradient is False:
- ndarray
an array of pixel values where the number of rows is the size of the neighborhood and there is a column for each voxel
- else if get_gradient is True:
- dictionary w/ following key-value pairs:
- valuesndarray
array of pixel values where the number of rows is the size of the neighborhood and there is a column for each voxel.
- gradientsndarray
array providing the gradients at the center voxel of each neighborhood
else if spatial_info is True–- dictionary w/ following key-value pairs:
- valuesndarray
array of pixel values where the number of rows is the size of the neighborhood and there is a column for each voxel.
- indicesndarray
array provinding the center coordinates for each neighborhood
- offsetsndarray
array providing the offsets from center for each voxel in a neighborhood
Example
>>> import ants >>> r16 = ants.image_read(ants.get_ants_data('r16')) >>> mask = ants.get_mask(r16) >>> mat = ants.get_neighborhood_in_mask(r16, mask, radius=(2,2))