ants.core.ants_transform
Functions
|
Apply ANTsTransform to data |
|
Apply transform to an image |
|
Apply transform to a point |
|
Apply transform to a vector |
|
Compose multiple ANTsTransform's together |
|
Get fixed parameters of an ANTsTransform |
|
Get parameters of an ANTsTransform |
|
Invert ANTsTransform |
Set fixed parameters of an ANTsTransform |
|
|
Set parameters of an ANTsTransform |
|
Get spatial point from index of an image. |
|
Get index from spatial point of an image. |
Classes
|
- class 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 (
ants.core.ANTsImage) – image to which the transform will be appliedreference (
ants.core.ANTsImage) – target space for transforming imageinterpolation (
str) –- 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
- 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 imagedata (
ndarray/list/tuple) – data to which transform will be applieddata_type (
str) –type of data Options :
’point’ ‘vector’ ‘image’
reference (
ants.core.ANTsImage) – target space for transforming imagekwargs (
kwargs) – additional options passed to apply_ants_transform_to_image
- Returns:
ANTsImage if data_type ==
'image'ORtuple if data_type ==
'point'or data_type =='vector'
- apply_ants_transform_to_image(transform, image, reference, interpolation='linear')[source]
Apply transform to an image
ANTsR function: applyAntsrTransformToImage
- Parameters:
image (
ants.core.ANTsImage) – image to which the transform will be appliedreference (
ants.core.ANTsImage) – reference imageinterpolation (
str) – 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)
- 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)
- 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
- compose_ants_transforms(transform_list)[source]
Compose multiple ANTsTransform’s together
ANTsR function: composeAntsrTransforms
- Parameters:
transform_list (
list/tupleofANTsTransform 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 )
- get_ants_transform_fixed_parameters(transform)[source]
Get fixed parameters of an ANTsTransform
ANTsR function: getAntsrTransformFixedParameters
- get_ants_transform_parameters(transform)[source]
Get parameters of an ANTsTransform
ANTsR function: getAntsrTransformParameters
- 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)
- set_ants_transform_fixed_parameters(transform, parameters)[source]
Set fixed parameters of an ANTsTransform
ANTsR function: setAntsrTransformFixedParameters
- set_ants_transform_parameters(transform, parameters)[source]
Set parameters of an ANTsTransform
ANTsR function: setAntsrTransformParameters
- transform_index_to_physical_point(image, index)[source]
Get spatial point from index of an image.
ANTsR function: antsTransformIndexToPhysicalPoint
- Parameters:
img (
ants.core.ANTsImage) – image to get values fromindex (
listortupleornumpy.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))
- transform_physical_point_to_index(image, point)[source]
Get index from spatial point of an image.
ANTsR function: antsTransformPhysicalPointToIndex
- Parameters:
image (
ants.core.ANTsImage) – image to get values frompoint (
listortupleornumpy.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))