ants.core package¶
Submodules¶
ants.core.ants_image module¶
- class ants.core.ants_image.ANTsImage(pixeltype='float', dimension=3, components=1, pointer=None, is_rgb=False)[source]¶
Bases:
object
- abp_n4(intensity_truncation=(0.025, 0.975, 256), mask=None, usen3=False)¶
- add_noise_to_image(noise_model, noise_parameters)¶
- anti_alias()¶
- apply(fn)[source]¶
Apply an arbitrary function to ANTsImage.
- Parameters:
fn (python function or lambda) – function to apply to ENTIRE image at once
- Returns:
image with function applied to it
- Return type:
- astype(dtype)[source]¶
Cast & clone an ANTsImage to a given numpy datatype.
- Map:
uint8 : unsigned char uint32 : unsigned int float32 : float float64 : double
- clone(pixeltype=None)[source]¶
Create a copy of the given ANTsImage with the same data and info, possibly with a different data type for the image data. Only supports casting to uint8 (unsigned char), uint32 (unsigned int), float32 (float), and float64 (double)
- Parameters:
dtype (string (optional)) –
if None, the dtype will be the same as the cloned ANTsImage. Otherwise, the data will be cast to this type. This can be a numpy type or an ITK type. Options:
’unsigned char’ or ‘uint8’, ‘unsigned int’ or ‘uint32’, ‘float’ or ‘float32’, ‘double’ or ‘float64’
- Return type:
- copy(pixeltype=None)¶
Create a copy of the given ANTsImage with the same data and info, possibly with a different data type for the image data. Only supports casting to uint8 (unsigned char), uint32 (unsigned int), float32 (float), and float64 (double)
- Parameters:
dtype (string (optional)) –
if None, the dtype will be the same as the cloned ANTsImage. Otherwise, the data will be cast to this type. This can be a numpy type or an ITK type. Options:
’unsigned char’ or ‘uint8’, ‘unsigned int’ or ‘uint32’, ‘float’ or ‘float32’, ‘double’ or ‘float64’
- Return type:
- create_tiled_mosaic(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)¶
- create_warped_grid(grid_step=10, grid_width=2, grid_directions=(True, True), fixed_reference_image=None, transform=None, foreground=1, background=0)¶
- crop_image(label_image=None, label=1)¶
- crop_indices(lowerind, upperind)¶
- decrop_image(full_image)¶
- denoise_image(mask=None, shrink_factor=1, p=1, r=3, noise_model='Rician', v=0)¶
- functional_lung_segmentation(mask=None, number_of_iterations=2, number_of_atropos_iterations=5, mrf_parameters='[0.7,2x2x2]', number_of_clusters=6, cluster_centers=None, bias_correction='n4', verbose=True)¶
- fuzzy_spatial_cmeans_segmentation(mask=None, number_of_clusters=4, m=2, p=1, q=1, radius=2, max_number_of_iterations=20, convergence_threshold=0.02, verbose=False)¶
- get_average_of_timeseries(idx=None)¶
- get_center_of_mass()¶
- get_centroids(clustparam=0)¶
- get_mask(low_thresh=None, high_thresh=None, cleanup=2)¶
- get_neighborhood_at_voxel(center, kernel, physical_coordinates=False)¶
- get_neighborhood_in_mask(mask, radius, physical_coordinates=False, boundary_condition=None, spatial_info=False, get_gradient=False)¶
- get_orientation()¶
- get_pointer_string()¶
- histogram_equalize_image(number_of_histogram_bins=256)¶
- iMath(operation, *args)¶
- iMath_GC(radius=1)¶
- iMath_GD(radius=1)¶
- iMath_GE(radius=1)¶
- iMath_GO(radius=1)¶
- iMath_MC(radius=1, value=1, shape=1, parametric=False, lines=3, thickness=1, include_center=False)¶
- iMath_MD(radius=1, value=1, shape=1, parametric=False, lines=3, thickness=1, include_center=False)¶
- iMath_ME(radius=1, value=1, shape=1, parametric=False, lines=3, thickness=1, include_center=False)¶
- iMath_MO(radius=1, value=1, shape=1, parametric=False, lines=3, thickness=1, include_center=False)¶
- iMath_canny(sigma, lower, upper)¶
- iMath_fill_holes(hole_type=2)¶
- iMath_get_largest_component(min_size=50)¶
- iMath_grad(sigma=0.5, normalize=False)¶
- iMath_histogram_equalization(alpha, beta)¶
- iMath_laplacian(sigma=0.5, normalize=False)¶
- iMath_maurer_distance(foreground=1)¶
- iMath_normalize()¶
- iMath_pad(padding)¶
- iMath_perona_malik(conductance=0.25, n_iterations=1)¶
- iMath_propagate_labels_through_mask(labels, stopping_value=100, propagation_method=0)¶
- iMath_sharpen()¶
- iMath_truncate_intensity(lower_q, upper_q, n_bins=64)¶
- image_math(operation, *args)¶
- image_to_cluster_images(min_cluster_size=50, min_thresh=1e-06, max_thresh=1)¶
- kmeans_segmentation(k, kmask=None, mrf=0.1)¶
- label_clusters(min_cluster_size=50, min_thresh=1e-06, max_thresh=1, fully_connected=False)¶
- label_image_centroids(physical=False, convex=True, verbose=False)¶
- label_stats(label_image)¶
- labels_to_matrix(mask, target_labels=None, missing_val=nan)¶
- list_to_ndimage(image_list)¶
- mask_image(mask, level=1, binarize=False)¶
- morphology(operation, radius, mtype='binary', value=1, shape='ball', radius_is_parametric=False, thickness=1, lines=3, include_center=False)¶
- motion_correction(fixed=None, type_of_transform='BOLDRigid', mask=None, fdOffset=50, outprefix='', verbose=False, **kwargs)¶
- movie(filename=None, writer=None, fps=30)¶
- multi_label_morphology(operation, radius, dilation_mask=None, label_list=None, force=False)¶
- n3_bias_field_correction(downsample_factor=3)¶
- n3_bias_field_correction2(mask=None, rescale_intensities=False, shrink_factor=4, convergence={'iters': 50, 'tol': 1e-07}, spline_param=None, number_of_fitting_levels=4, return_bias_field=False, verbose=False, weight_mask=None)¶
- n4_bias_field_correction(mask=None, rescale_intensities=False, shrink_factor=4, convergence={'iters': [50, 50, 50, 50], 'tol': 1e-07}, spline_param=None, return_bias_field=False, verbose=False, weight_mask=None)¶
- ndimage_to_list()¶
- new_image_like(data)[source]¶
Create a new ANTsImage with the same header information, but with a new image array.
- Parameters:
data (ndarray or py::capsule) – New array or pointer for the image. It must have the same shape as the current image data.
- Return type:
- numpy(single_components=False)[source]¶
Get a numpy array copy representing the underlying image data. Altering this ndarray will have NO effect on the underlying image data.
- Parameters:
single_components (boolean (default is False)) – if True, keep the extra component dimension in returned array even if image only has one component (i.e. self.has_components == False)
- Return type:
ndarray
- property orientation¶
- otsu_segmentation(k, mask=None)¶
- pad_image(shape=None, pad_width=None, value=0.0, return_padvals=False)¶
- plot(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)¶
- plot_hist(threshold=0.0, fit_line=False, normfreq=True, title=None, grid=True, xlabel=None, ylabel=None, facecolor='green', alpha=0.75)¶
- plot_ortho(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, cbar=False, cbar_length=0.8, cbar_dx=0.0, cbar_vertical=True, 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, allow_xyz_change=True)¶
- prior_based_segmentation(priors, mask, priorweight=0.25, mrf=0.1, iterations=25)¶
- quantile(q, nonzero=True)¶
- reflect_image(axis=None, tx=None, metric='mattes')¶
- reorient_image2(orientation='RAS')¶
- resample_image(resample_params, use_voxels=False, interp_type=1)¶
- resample_image_to_target(target, interp_type='linear', imagetype=0, verbose=False, **kwargs)¶
- rgb_to_vector()¶
- scalar_to_rgb(mask=None, filename=None, cmap='red', custom_colormap_file=None, min_input=None, max_input=None, min_rgb_output=None, max_rgb_output=None, vtk_lookup_table=None)¶
- set_direction(new_direction)[source]¶
Set image direction
- Parameters:
new_direction (numpy.ndarray or tuple or list) – updated direction for the image. should have one value for each dimension
- Return type:
None
- slice_image(axis, idx, collapse_strategy=0)¶
- smooth_image(sigma, sigma_in_physical_coordinates=True, FWHM=False, max_kernel_width=32)¶
- split_channels()¶
- symmetrize_image()¶
- threshold_image(low_thresh=None, high_thresh=None, inval=1, outval=0, binary=True)¶
- to_file(filename)[source]¶
Write the ANTsImage to file
- Parameters:
filename (string) – filepath to which the image will be written
- to_filename(filename)¶
Write the ANTsImage to file
- Parameters:
filename (string) – filepath to which the image will be written
- to_nibabel()¶
- vector_to_rgb()¶
- view(single_components=False)[source]¶
Geet a numpy array providing direct, shared access to the image data. IMPORTANT: If you alter the view, then the underlying image data will also be altered.
- Parameters:
single_components (boolean (default is False)) – if True, keep the extra component dimension in returned array even if image only has one component (i.e. self.has_components == False)
- Return type:
ndarray
- weingarten_image_curvature(sigma=1.0, opt='mean')¶
- ants.core.ants_image.allclose(image1, image2)[source]¶
Check if two images have the same array values
- ants.core.ants_image.copy_image_info(reference, target)[source]¶
Copy origin, direction, and spacing from one antsImage to another
ANTsR function: antsCopyImageInfo
- ants.core.ants_image.get_direction(image)[source]¶
Get direction of ANTsImage
ANTsR function: antsGetDirection
- ants.core.ants_image.get_origin(image)[source]¶
Get origin of ANTsImage
ANTsR function: antsGetOrigin
- ants.core.ants_image.get_spacing(image)[source]¶
Get spacing of ANTsImage
ANTsR function: antsGetSpacing
- ants.core.ants_image.image_physical_space_consistency(image1, image2, tolerance=0.01, datatype=False)[source]¶
Check if two or more ANTsImage objects occupy the same physical space
ANTsR function: antsImagePhysicalSpaceConsistency
- Parameters:
*images (ANTsImages) – images to compare
tolerance (float) – tolerance when checking origin and spacing
data_type (boolean) – If true, also check that the image data types are the same
- Returns:
true if images share same physical space, false otherwise
- Return type:
boolean
- ants.core.ants_image.image_type_cast(image_list, pixeltype=None)[source]¶
Cast a list of images to the highest pixeltype present in the list or all to a specified type
ANTsR function: antsImageTypeCast
- Parameters:
image_list (list/tuple) – images to cast
pixeltype (string (optional)) – pixeltype to cast to. If None, images will be cast to the highest precision pixeltype found in image_list
- Returns:
given images casted to new type
- Return type:
list of ANTsImages
- ants.core.ants_image.set_direction(image, direction)[source]¶
Set direction of ANTsImage
ANTsR function: antsSetDirection
ants.core.ants_image_io module¶
Image IO
- ants.core.ants_image_io.dicom_read(directory, pixeltype='float')[source]¶
Read a set of dicom files in a directory into a single ANTsImage. The origin of the resulting 3D image will be the origin of the first dicom image read.
- Parameters:
directory (string) – folder in which all the dicom images exist
- Return type:
Example
>>> import ants >>> img = ants.dicom_read('~/desktop/dicom-subject/')
- ants.core.ants_image_io.from_numpy(data, origin=None, spacing=None, direction=None, has_components=False, is_rgb=False)[source]¶
Create an ANTsImage object from a numpy array
ANTsR function: as.antsImage
- Parameters:
data (ndarray) – image data array
origin (tuple/list) – image origin
spacing (tuple/list) – image spacing
direction (list/ndarray) – image direction
has_components (boolean) – whether the image has components
- Returns:
image with given data and any given information
- Return type:
- ants.core.ants_image_io.image_clone(image, pixeltype=None)[source]¶
Clone an ANTsImage
ANTsR function: antsImageClone
- ants.core.ants_image_io.image_header_info(filename)[source]¶
Read file info from image header
ANTsR function: antsImageHeaderInfo
- Parameters:
filename (string) – name of image file from which info will be read
- Return type:
- ants.core.ants_image_io.image_list_to_matrix(image_list, mask=None, sigma=None, epsilon=0.5)¶
Read images into rows of a matrix, given a mask - much faster for large datasets as it is based on C++ implementations.
ANTsR function: imagesToMatrix
- Parameters:
- Returns:
array with a row for each image shape = (N_IMAGES, N_VOXELS)
- Return type:
ndarray
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> img2 = ants.image_read(ants.get_ants_data('r16')) >>> img3 = ants.image_read(ants.get_ants_data('r16')) >>> mat = ants.image_list_to_matrix([img,img2,img3])
- ants.core.ants_image_io.image_read(filename, dimension=None, pixeltype='float', reorient=False)[source]¶
Read an ANTsImage from file
ANTsR function: antsImageRead
- Parameters:
filename (string) – Name of the file to read the image from.
dimension (int) – Number of dimensions of the image read. This need not be the same as the dimensions of the image in the file. Allowed values: 2, 3, 4. If not provided, the dimension is obtained from the image file
pixeltype (string) – C++ datatype to be used to represent the pixels read. This datatype need not be the same as the datatype used in the file. Options: unsigned char, unsigned int, float, double
reorient (boolean | string) –
if True, the image will be reoriented to RPI if it is 3D if False, nothing will happen if string, this should be the 3-letter orientation to which the
input image will reoriented if 3D.
if the image is 2D, this argument is ignored
- Return type:
- ants.core.ants_image_io.image_write(image, filename, ri=False)[source]¶
Write an ANTsImage to file
ANTsR function: antsImageWrite
- Parameters:
image (ANTsImage) – image to save to file
filename (string) – name of file to which image will be saved
ri (boolean) –
- if True, return image. This allows for using this function in a pipeline:
>>> img2 = img.smooth_image(2.).image_write(file1, ri=True).threshold_image(0,20).image_write(file2, ri=True)
if False, do not return image
- ants.core.ants_image_io.images_from_matrix(data_matrix, mask)¶
Unmasks rows of a matrix and writes as images
ANTsR function: matrixToImages
- Parameters:
data_matrix (numpy.ndarray) – each row corresponds to an image array should have number of columns equal to non-zero voxels in the mask
mask (ANTsImage) – image containing a binary mask. Rows of the matrix are unmasked and written as images. The mask defines the output image space
- Return type:
list of ANTsImage types
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> msk = ants.get_mask( img ) >>> img2 = ants.image_read(ants.get_ants_data('r16')) >>> img3 = ants.image_read(ants.get_ants_data('r16')) >>> mat = ants.image_list_to_matrix([img,img2,img3], msk ) >>> ilist = ants.matrix_to_images( mat, msk )
- ants.core.ants_image_io.images_to_matrix(image_list, mask=None, sigma=None, epsilon=0.5)[source]¶
Read images into rows of a matrix, given a mask - much faster for large datasets as it is based on C++ implementations.
ANTsR function: imagesToMatrix
- Parameters:
- Returns:
array with a row for each image shape = (N_IMAGES, N_VOXELS)
- Return type:
ndarray
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> img2 = ants.image_read(ants.get_ants_data('r16')) >>> img3 = ants.image_read(ants.get_ants_data('r16')) >>> mat = ants.image_list_to_matrix([img,img2,img3])
- ants.core.ants_image_io.make_image(imagesize, voxval=0, spacing=None, origin=None, direction=None, has_components=False, pixeltype='float')[source]¶
Make an image with given size and voxel value or given a mask and vector
ANTsR function: makeImage
- Parameters:
shape (tuple/ANTsImage) – input image size or mask
voxval (scalar) – input image value or vector, size of mask
spacing (tuple/list) – image spatial resolution
origin (tuple/list) – image spatial origin
direction (list/ndarray) – direction matrix to convert from index to physical space
components (boolean) – whether there are components per pixel or not
pixeltype (float) – data type of image values
- Return type:
- ants.core.ants_image_io.matrix_from_images(image_list, mask=None, sigma=None, epsilon=0.5)¶
Read images into rows of a matrix, given a mask - much faster for large datasets as it is based on C++ implementations.
ANTsR function: imagesToMatrix
- Parameters:
- Returns:
array with a row for each image shape = (N_IMAGES, N_VOXELS)
- Return type:
ndarray
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> img2 = ants.image_read(ants.get_ants_data('r16')) >>> img3 = ants.image_read(ants.get_ants_data('r16')) >>> mat = ants.image_list_to_matrix([img,img2,img3])
- ants.core.ants_image_io.matrix_to_images(data_matrix, mask)[source]¶
Unmasks rows of a matrix and writes as images
ANTsR function: matrixToImages
- Parameters:
data_matrix (numpy.ndarray) – each row corresponds to an image array should have number of columns equal to non-zero voxels in the mask
mask (ANTsImage) – image containing a binary mask. Rows of the matrix are unmasked and written as images. The mask defines the output image space
- Return type:
list of ANTsImage types
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data('r16')) >>> msk = ants.get_mask( img ) >>> img2 = ants.image_read(ants.get_ants_data('r16')) >>> img3 = ants.image_read(ants.get_ants_data('r16')) >>> mat = ants.image_list_to_matrix([img,img2,img3], msk ) >>> ilist = ants.matrix_to_images( mat, msk )
- ants.core.ants_image_io.matrix_to_timeseries(image, matrix, mask=None)[source]¶
converts a matrix to a ND image.
ANTsR function: matrix2timeseries
- Parameters:
image (reference ND image) –
matrix (matrix to convert to image) –
mask (mask image defining voxels of python:interest) –
- Return type:
Example
>>> import ants >>> img = ants.make_image( (10,10,10,5 ) ) >>> mask = ants.ndimage_to_list( img )[0] * 0 >>> mask[ 4:8, 4:8, 4:8 ] = 1 >>> mat = ants.timeseries_to_matrix( img, mask = mask ) >>> img2 = ants.matrix_to_timeseries( img, mat, mask)
- ants.core.ants_image_io.timeseries_to_matrix(image, mask=None)[source]¶
Convert a timeseries image into a matrix.
ANTsR function: timeseries2matrix
- Parameters:
image (image whose slices we convert to a matrix. E.g. a 3D image of size) – x by y by z will convert to a z by x*y sized matrix
mask (ANTsImage (optional)) – image containing binary mask. voxels in the mask are placed in the matrix
- Returns:
array with a row for each image shape = (N_IMAGES, N_VOXELS)
- Return type:
ndarray
Example
>>> import ants >>> img = ants.make_image( (10,10,10,5 ) ) >>> mat = ants.timeseries_to_matrix( img )
ants.core.ants_metric module¶
ANTs ImageToImageMetric class
ants.core.ants_metric_io module¶
- ants.core.ants_metric_io.create_ants_metric(fixed, moving, metric_type='MeanSquares', fixed_mask=None, moving_mask=None, sampling_strategy='regular', sampling_percentage=1)[source]¶
- Parameters:
metric_type (string) –
which metric to use options:
MeanSquares MattesMutualInformation ANTSNeighborhoodCorrelation Correlation Demons JointHistogramMutualInformation
Example
>>> import ants >>> fixed = ants.image_read(ants.get_ants_data('r16')) >>> moving = ants.image_read(ants.get_ants_data('r64')) >>> metric_type = 'Correlation' >>> metric = ants.create_ants_metric(fixed, moving, metric_type)
ants.core.ants_transform module¶
- class ants.core.ants_transform.ANTsTransform(precision='float', dimension=3, transform_type='AffineTransform', pointer=None)[source]¶
Bases:
object
- apply_to_image(image, reference=None, interpolation='linear')[source]¶
Apply transform to an image
- Parameters:
image (ANTsImage) – image to which the transform will be applied
reference (ANTsImage) – target space for transforming image
interpolation (string) –
- type of interpolation to use. Options are:
linear nearestneighbor multilabel gaussian bspline cosinewindowedsinc welchwindowedsinc hammingwindoweddinc lanczoswindowedsinc genericlabel
- Returns:
list
- Return type:
transformed vector
- apply_to_point(point)[source]¶
Apply transform to a point
- Parameters:
point (list/tuple) – point to which the transform will be applied
- Returns:
list
- Return type:
transformed point
Example
>>> import ants >>> tx = ants.new_ants_transform() >>> params = tx.parameters >>> tx.set_parameters(params*2) >>> pt2 = tx.apply_to_point((1,2,3)) # should be (2,4,6)
- apply_to_vector(vector)[source]¶
Apply transform to a vector
- Parameters:
vector (list/tuple) – vector to which the transform will be applied
- Returns:
list
- Return type:
transformed vector
- property fixed_parameters¶
Get parameters of transform
- property parameters¶
Get parameters of transform
- ants.core.ants_transform.apply_ants_transform(transform, data, data_type='point', reference=None, **kwargs)[source]¶
Apply ANTsTransform to data
ANTsR function: applyAntsrTransform
- Parameters:
transform (ANTsTransform) – transform to apply to image
data (ndarray/list/tuple) – data to which transform will be applied
data_type (string) –
type of data Options :
’point’ ‘vector’ ‘image’
reference (ANTsImage) – target space for transforming image
kwargs (kwargs) – additional options passed to apply_ants_transform_to_image
- Returns:
ANTsImage if data_type == ‘point’
OR
tuple if data_type == ‘point’ or data_type == ‘vector’
- ants.core.ants_transform.apply_ants_transform_to_image(transform, image, reference, interpolation='linear')[source]¶
Apply transform to an image
ANTsR function: applyAntsrTransformToImage
- Parameters:
image (ANTsImage) – image to which the transform will be applied
reference (ANTsImage) – reference image
interpolation (string) – type of interpolation to use. Options are: linear nearestneighbor multilabel gaussian bspline cosinewindowedsinc welchwindowedsinc hammingwindoweddinc lanczoswindowedsinc genericlabel
- Returns:
list
- Return type:
transformed vector
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data("r16")).clone('float') >>> tx = ants.new_ants_transform(dimension=2) >>> tx.set_parameters((0.9,0,0,1.1,10,11)) >>> img2 = tx.apply_to_image(img, img)
- ants.core.ants_transform.apply_ants_transform_to_point(transform, point)[source]¶
Apply transform to a point
ANTsR function: applyAntsrTransformToPoint
- Parameters:
point (list/tuple) – point to which the transform will be applied
- Returns:
tuple
- Return type:
transformed point
Example
>>> import ants >>> tx = ants.new_ants_transform() >>> params = tx.parameters >>> tx.set_parameters(params*2) >>> pt2 = tx.apply_to_point((1,2,3)) # should be (2,4,6)
- ants.core.ants_transform.apply_ants_transform_to_vector(transform, vector)[source]¶
Apply transform to a vector
ANTsR function: applyAntsrTransformToVector
- Parameters:
vector (list/tuple) – vector to which the transform will be applied
- Returns:
tuple
- Return type:
transformed vector
- ants.core.ants_transform.compose_ants_transforms(transform_list)[source]¶
Compose multiple ANTsTransform’s together
ANTsR function: composeAntsrTransforms
- Parameters:
transform_list (list/tuple of ANTsTransform object) – list of transforms to compose together
- Returns:
one transform that contains all given transforms
- Return type:
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data("r16")).clone('float') >>> tx = ants.new_ants_transform(dimension=2) >>> tx.set_parameters((0.9,0,0,1.1,10,11)) >>> inv_tx = tx.invert() >>> single_tx = ants.compose_ants_transforms([tx, inv_tx]) >>> img_orig = single_tx.apply_to_image(img, img) >>> rRotGenerator = ants.contrib.RandomRotate2D( ( 0, 40 ), reference=img ) >>> rShearGenerator=ants.contrib.RandomShear2D( (0,50), reference=img ) >>> tx1 = rRotGenerator.transform() >>> tx2 = rShearGenerator.transform() >>> rSrR = ants.compose_ants_transforms([tx1, tx2]) >>> rSrR.apply_to_image( img )
- ants.core.ants_transform.get_ants_transform_fixed_parameters(transform)[source]¶
Get fixed parameters of an ANTsTransform
ANTsR function: getAntsrTransformFixedParameters
- ants.core.ants_transform.get_ants_transform_parameters(transform)[source]¶
Get parameters of an ANTsTransform
ANTsR function: getAntsrTransformParameters
- ants.core.ants_transform.invert_ants_transform(transform)[source]¶
Invert ANTsTransform
ANTsR function: invertAntsrTransform
Example
>>> import ants >>> img = ants.image_read(ants.get_ants_data("r16")).clone('float') >>> tx = ants.new_ants_transform(dimension=2) >>> tx.set_parameters((0.9,0,0,1.1,10,11)) >>> img_transformed = tx.apply_to_image(img, img) >>> inv_tx = tx.invert() >>> img_orig = inv_tx.apply_to_image(img_transformed, img_transformed)
- ants.core.ants_transform.set_ants_transform_fixed_parameters(transform, parameters)[source]¶
Set fixed parameters of an ANTsTransform
ANTsR function: setAntsrTransformFixedParameters
- ants.core.ants_transform.set_ants_transform_parameters(transform, parameters)[source]¶
Set parameters of an ANTsTransform
ANTsR function: setAntsrTransformParameters
- ants.core.ants_transform.transform_index_to_physical_point(image, index)[source]¶
Get spatial point from index of an image.
ANTsR function: antsTransformIndexToPhysicalPoint
- Parameters:
img (ANTsImage) – image to get values from
index (list or tuple or numpy.ndarray) – location in image
- Return type:
Example
>>> import ants >>> import numpy as np >>> img = ants.make_image((10,10),np.random.randn(100)) >>> pt = ants.transform_index_to_physical_point(img, (2,2))
- ants.core.ants_transform.transform_physical_point_to_index(image, point)[source]¶
Get index from spatial point of an image.
ANTsR function: antsTransformPhysicalPointToIndex
- Parameters:
image (ANTsImage) – image to get values from
point (list or tuple or numpy.ndarray) – point in image
- Return type:
Example
>>> import ants >>> import numpy as np >>> img = ants.make_image((10,10),np.random.randn(100)) >>> idx = ants.transform_physical_point_to_index(img, (2,2)) >>> img.set_spacing((2,2)) >>> idx2 = ants.transform_physical_point_to_index(img, (4,4))
ants.core.ants_transform_io module¶
- ants.core.ants_transform_io.create_ants_transform(transform_type='AffineTransform', precision='float', dimension=3, matrix=None, offset=None, center=None, translation=None, parameters=None, fixed_parameters=None, displacement_field=None, supported_types=False)[source]¶
Create and initialize an ANTsTransform
ANTsR function: createAntsrTransform
- Parameters:
transform_type (string) – type of transform(s)
precision (string) – numerical precision
dimension (python:integer) – spatial dimension of transform
matrix (ndarray) – matrix for linear transforms
offset (tuple/list) – offset for linear transforms
center (tuple/list) – center for linear transforms
translation (tuple/list) – translation for linear transforms
parameters (ndarray/list) – array of parameters
fixed_parameters (ndarray/list) – array of fixed parameters
displacement_field (ANTsImage) – multichannel ANTsImage for non-linear transform
supported_types (boolean) – flag that returns array of possible transforms types
- Return type:
ANTsTransform or list of ANTsTransform types
Example
>>> import ants >>> translation = (3,4,5) >>> tx = ants.create_ants_transform( type='Euler3DTransform', translation=translation )
- ants.core.ants_transform_io.new_ants_transform(precision='float', dimension=3, transform_type='AffineTransform', parameters=None, fixed_parameters=None)[source]¶
Create a new ANTsTransform
ANTsR function: None
This is a simplified method for creating an ANTsTransform, mostly used internally. See create_ants_transform for more options.
Example
>>> import ants >>> tx = ants.new_ants_transform()
- ants.core.ants_transform_io.read_transform(filename, precision='float')[source]¶
Read a transform from file
ANTsR function: readAntsrTransform
- Parameters:
filename (string) – filename of transform
precision (string) – numerical precision of transform
- Return type:
Example
>>> import ants >>> tx = ants.new_ants_transform(dimension=2) >>> tx.set_parameters((0.9,0,0,1.1,10,11)) >>> ants.write_transform(tx, '~/desktop/tx.mat') >>> tx2 = ants.read_transform('~/desktop/tx.mat')
- ants.core.ants_transform_io.transform_from_displacement_field(field)[source]¶
Convert deformation field (multiChannel image) to ANTsTransform
ANTsR function: antsrTransformFromDisplacementField
Example
>>> import ants >>> fi = ants.image_read(ants.get_ants_data('r16') ) >>> mi = ants.image_read(ants.get_ants_data('r64') ) >>> fi = ants.resample_image(fi,(60,60),1,0) >>> mi = ants.resample_image(mi,(60,60),1,0) # speed up >>> mytx = ants.registration(fixed=fi, moving=mi, type_of_transform = ('SyN') ) >>> vec = ants.image_read( mytx['fwdtransforms'][0] ) >>> atx = ants.transform_from_displacement_field( vec )
- ants.core.ants_transform_io.transform_to_displacement_field(xfrm, ref)[source]¶
Convert displacement field ANTsTransform to displacement field
ANTsR function: antsrTransformToDisplacementField
- Parameters:
xfrm (displacement field ANTsTransform) – displacement field ANTsTransform
ref (ANTs Image) –
- Return type:
ANTsVectorImage
Example
>>> import ants >>> fi = ants.image_read(ants.get_ants_data('r16') ) >>> mi = ants.image_read(ants.get_ants_data('r64') ) >>> fi = ants.resample_image(fi,(60,60),1,0) >>> mi = ants.resample_image(mi,(60,60),1,0) # speed up >>> mytx = ants.registration(fixed=fi, moving=mi, type_of_transform = ('SyN') ) >>> vec = ants.image_read( mytx['fwdtransforms'][0] ) >>> atx = ants.transform_from_displacement_field( vec ) >>> field = ants.transform_to_displacement_field( atx, fi )
- ants.core.ants_transform_io.write_transform(transform, filename)[source]¶
Write ANTsTransform to file
ANTsR function: writeAntsrTransform
- Parameters:
transform (ANTsTransform) – transform to save
filename (string) – filename of transform (file extension is “.mat” for affine transforms)
- Return type:
N/A
Example
>>> import ants >>> tx = ants.new_ants_transform(dimension=2) >>> tx.set_parameters((0.9,0,0,1.1,10,11)) >>> ants.write_transform(tx, '~/desktop/tx.mat') >>> tx2 = ants.read_transform('~/desktop/tx.mat')