ants.contrib.sampling.affine2d

Affine transforms

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

Classes

RandomRotate2D(rotation_range[, reference, lazy])

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

RandomShear2D(shear_range[, reference, lazy])

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

RandomTranslate2D(translation_range[, ...])

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

RandomZoom2D(zoom_range[, reference, lazy])

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

Rotate2D(rotation[, reference, lazy])

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

Shear2D(shear[, reference, lazy])

Create an ANTs Affine Transform with a specified shear.

Translate2D(translation[, reference, lazy])

Create an ANTs Affine Transform with a specified translation.

Zoom2D(zoom[, reference, lazy])

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

class RandomRotate2D(rotation_range, reference=None, lazy=False)[source]

Bases: object

Apply a Rotated2D 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('r16'))
>>> tx = ants.contrib.RandomRotate2D(rotation_range=(-10,10))
>>> img2 = tx.transform(img)
class RandomShear2D(shear_range, reference=None, lazy=False)[source]

Bases: object

Apply a Shear2D 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('r16'))
>>> tx = ants.contrib.RandomShear2D(shear_range=(-10,10))
>>> img2 = tx.transform(img)
class RandomTranslate2D(translation_range, reference=None, lazy=False)[source]

Bases: object

Apply a Translate2D transform to an image, but with the 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('r16'))
>>> tx = ants.contrib.RandomShear2D(translation_range=(-10,10))
>>> img2 = tx.transform(img)
class RandomZoom2D(zoom_range, reference=None, lazy=False)[source]

Bases: object

Apply a Zoom2D 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('r16'))
>>> tx = ants.contrib.RandomZoom2D(zoom_range=(0.8,0.9))
>>> img2 = tx.transform(img)
class Rotate2D(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('r16'))
>>> tx = ants.contrib.Rotate2D(rotation=(10,-5,12))
>>> img2 = tx.transform(img)
class Shear2D(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('r16'))
>>> tx = ants.contrib.Shear2D(shear=(10,0,0))
>>> img2_x = tx.transform(img)# x axis stays same
>>> tx = ants.contrib.Shear2D(shear=(-10,0,0)) # other direction
>>> img2_x = tx.transform(img)# x axis stays same
>>> tx = ants.contrib.Shear2D(shear=(0,10,0))
>>> img2_y = tx.transform(img) # y axis stays same
>>> tx = ants.contrib.Shear2D(shear=(0,0,10))
>>> img2_z = tx.transform(img) # z axis stays same
>>> tx = ants.contrib.Shear2D(shear=(10,10,10))
>>> img2 = tx.transform(img)
class Translate2D(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('r16'))
>>> tx = ants.contrib.Translate2D(translation=(10,0))
>>> img2_x = tx.transform(img)
>>> tx = ants.contrib.Translate2D(translation=(-10,0)) # other direction
>>> img2_x = tx.transform(img)
>>> tx = ants.contrib.Translate2D(translation=(0,10))
>>> img2_z = tx.transform(img)
>>> tx = ants.contrib.Translate2D(translation=(10,10))
>>> img2 = tx.transform(img)
class Zoom2D(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('r16'))
>>> tx = ants.contrib.Zoom2D(zoom=(0.8,0.8,0.8))
>>> img2 = tx.transform(img)