ants.contrib.sampling.affine3d

Affine transforms

See http://www.cs.cornell.edu/courses/cs4620/2010fa/lectures/03transforms3d.pdf

Classes

Affine3D(transformation[, reference, lazy])

Create a specified ANTs Affine Transform

RandomRotate3D(rotation_range[, reference, lazy])

Apply a Rotate3D transform to an image, but with the zoom parameters randomly generated from a user-specified range.

RandomShear3D(shear_range[, reference, lazy])

Apply a Shear3D transform to an image, but with the shear parameters randomly generated from a user-specified range.

RandomTranslate3D(translation_range[, ...])

Apply a Translate3D transform to an image, but with the shear parameters randomly generated from a user-specified range.

RandomZoom3D(zoom_range[, reference, lazy])

Apply a Zoom3D transform to an image, but with the zoom parameters randomly generated from a user-specified range.

Rotate3D(rotation[, reference, lazy])

Create an ANTs Affine Transform with a specified level of rotation.

Shear3D(shear[, reference, lazy])

Create an ANTs Affine Transform with a specified shear.

Translate3D(translation[, reference, lazy])

Create an ANTs Affine Transform with a specified translation.

Zoom3D(zoom[, reference, lazy])

Create an ANTs Affine Transform with a specified level of zoom.

class Affine3D(transformation, reference=None, lazy=False)[source]

Bases: object

Create a specified ANTs Affine Transform

transform(X=None, y=None)[source]

Transform an image using an Affine transform with the given translation parameters. Return the transform if X=None.

Parameters:
  • X (ants.core.ANTsImage) – Image to transform

  • y (ANTsImage (optional)) – Another image to transform

Return type:

ANTsImage if y is None, else a tuple of ANTsImage types

Examples

>>> import ants
>>> img = ants.image_read(ants.get_data('ch2'))
>>> tx = ants.contrib.Affine3D(transformation=np.array([[1, 0, 0, dx], [0, 1, 0, dy],[0, 0, 1, dz]])
>>> img2_x = tx.transform(img)# image translated by (dx, dy, dz)
class RandomRotate3D(rotation_range, reference=None, lazy=False)[source]

Bases: object

Apply a Rotate3D transform to an image, but with the zoom parameters randomly generated from a user-specified range. The range is determined by a mean (first parameter) and standard deviation (second parameter) via calls to random.gauss.

transform(X=None, y=None)[source]

Transform an image using an Affine transform with rotation parameters randomly generated from the user-specified range. Return the transform if X=None.

Parameters:
  • X (ants.core.ANTsImage) – Image to transform

  • y (ANTsImage (optional)) – Another image to transform

Return type:

ANTsImage if y is None, else a tuple of ANTsImage types

Examples

>>> import ants
>>> img = ants.image_read(ants.get_data('ch2'))
>>> tx = ants.contrib.RandomRotate3D(rotation_range=(-10,10))
>>> img2 = tx.transform(img)
class RandomShear3D(shear_range, reference=None, lazy=False)[source]

Bases: object

Apply a Shear3D transform to an image, but with the shear parameters randomly generated from a user-specified range. The range is determined by a mean (first parameter) and standard deviation (second parameter) via calls to random.gauss.

transform(X=None, y=None)[source]

Transform an image using an Affine transform with shear parameters randomly generated from the user-specified range. Return the transform if X=None.

Parameters:
  • X (ants.core.ANTsImage) – Image to transform

  • y (ANTsImage (optional)) – Another image to transform

Return type:

ANTsImage if y is None, else a tuple of ANTsImage types

Examples

>>> import ants
>>> img = ants.image_read(ants.get_data('ch2'))
>>> tx = ants.contrib.RandomShear3D(shear_range=(-10,10))
>>> img2 = tx.transform(img)
class RandomTranslate3D(translation_range, reference=None, lazy=False)[source]

Bases: object

Apply a Translate3D transform to an image, but with the shear parameters randomly generated from a user-specified range. The range is determined by a mean (first parameter) and standard deviation (second parameter) via calls to random.gauss.

transform(X=None, y=None)[source]

Transform an image using an Affine transform with translation parameters randomly generated from the user-specified range. Return the transform if X=None.

Parameters:
  • X (ants.core.ANTsImage) – Image to transform

  • y (ANTsImage (optional)) – Another image to transform

Return type:

ANTsImage if y is None, else a tuple of ANTsImage types

Examples

>>> import ants
>>> img = ants.image_read(ants.get_data('ch2'))
>>> tx = ants.contrib.RandomShear3D(translation_range=(-10,10))
>>> img2 = tx.transform(img)
class RandomZoom3D(zoom_range, reference=None, lazy=False)[source]

Bases: object

Apply a Zoom3D transform to an image, but with the zoom parameters randomly generated from a user-specified range. The range is determined by a mean (first parameter) and standard deviation (second parameter) via calls to random.gauss.

transform(X=None, y=None)[source]

Transform an image using an Affine transform with zoom parameters randomly generated from the user-specified range. Return the transform if X=None.

Parameters:
  • X (ants.core.ANTsImage) – Image to transform

  • y (ANTsImage (optional)) – Another image to transform

Return type:

ANTsImage if y is None, else a tuple of ANTsImage types

Examples

>>> import ants
>>> img = ants.image_read(ants.get_data('ch2'))
>>> tx = ants.contrib.RandomZoom3D(zoom_range=(0.8,0.9))
>>> img2 = tx.transform(img)
class Rotate3D(rotation, reference=None, lazy=False)[source]

Bases: object

Create an ANTs Affine Transform with a specified level of rotation.

transform(X=None, y=None)[source]

Transform an image using an Affine transform with the given rotation parameters. Return the transform if X=None.

Parameters:
  • X (ants.core.ANTsImage) – Image to transform

  • y (ANTsImage (optional)) – Another image to transform

Return type:

ANTsImage if y is None, else a tuple of ANTsImage types

Examples

>>> import ants
>>> img = ants.image_read(ants.get_data('ch2'))
>>> tx = ants.contrib.Rotate3D(rotation=(10,-5,12))
>>> img2 = tx.transform(img)
class Shear3D(shear, reference=None, lazy=False)[source]

Bases: object

Create an ANTs Affine Transform with a specified shear.

transform(X=None, y=None)[source]

Transform an image using an Affine transform with the given shear parameters. Return the transform if X=None.

Parameters:
  • X (ants.core.ANTsImage) – Image to transform

  • y (ANTsImage (optional)) – Another image to transform

Return type:

ANTsImage if y is None, else a tuple of ANTsImage types

Examples

>>> import ants
>>> img = ants.image_read(ants.get_data('ch2'))
>>> tx = ants.contrib.Shear3D(shear=(10,0,0))
>>> img2_x = tx.transform(img)# x axis stays same
>>> tx = ants.contrib.Shear3D(shear=(-10,0,0)) # other direction
>>> img2_x = tx.transform(img)# x axis stays same
>>> tx = ants.contrib.Shear3D(shear=(0,10,0))
>>> img2_y = tx.transform(img) # y axis stays same
>>> tx = ants.contrib.Shear3D(shear=(0,0,10))
>>> img2_z = tx.transform(img) # z axis stays same
>>> tx = ants.contrib.Shear3D(shear=(10,10,10))
>>> img2 = tx.transform(img)
class Translate3D(translation, reference=None, lazy=False)[source]

Bases: object

Create an ANTs Affine Transform with a specified translation.

transform(X=None, y=None)[source]

Transform an image using an Affine transform with the given translation parameters. Return the transform if X=None.

Parameters:
  • X (ants.core.ANTsImage) – Image to transform

  • y (ANTsImage (optional)) – Another image to transform

Return type:

ANTsImage if y is None, else a tuple of ANTsImage types

Examples

>>> import ants
>>> img = ants.image_read(ants.get_data('ch2'))
>>> tx = ants.contrib.Translate3D(translation=(10,0,0))
>>> img2_x = tx.transform(img)# x axis stays same
>>> tx = ants.contrib.Translate3D(translation=(-10,0,0)) # other direction
>>> img2_x = tx.transform(img)# x axis stays same
>>> tx = ants.contrib.Translate3D(translation=(0,10,0))
>>> img2_y = tx.transform(img) # y axis stays same
>>> tx = ants.contrib.Translate3D(translation=(0,0,10))
>>> img2_z = tx.transform(img) # z axis stays same
>>> tx = ants.contrib.Translate3D(translation=(10,10,10))
>>> img2 = tx.transform(img)
class Zoom3D(zoom, reference=None, lazy=False)[source]

Bases: object

Create an ANTs Affine Transform with a specified level of zoom. Any value greater than 1 implies a “zoom-out” and anything less than 1 implies a “zoom-in”.

transform(X=None, y=None)[source]

Transform an image using an Affine transform with the given zoom parameters. Return the transform if X=None.

Parameters:
  • X (ants.core.ANTsImage) – Image to transform

  • y (ANTsImage (optional)) – Another image to transform

Return type:

ANTsImage if y is None, else a tuple of ANTsImage types

Examples

>>> import ants
>>> img = ants.image_read(ants.get_data('ch2'))
>>> tx = ants.contrib.Zoom3D(zoom=(0.8,0.8,0.8))
>>> img2 = tx.transform(img)