ants.contrib.sampling package

Submodules

ants.contrib.sampling.affine2d module

Affine transforms

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

class ants.contrib.sampling.affine2d.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 (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 ants.contrib.sampling.affine2d.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 (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 ants.contrib.sampling.affine2d.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 (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 ants.contrib.sampling.affine2d.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 (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 ants.contrib.sampling.affine2d.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 (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 ants.contrib.sampling.affine2d.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 (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 ants.contrib.sampling.affine2d.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 (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 ants.contrib.sampling.affine2d.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 (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)

ants.contrib.sampling.affine3d module

Affine transforms

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

class ants.contrib.sampling.affine3d.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 (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 ants.contrib.sampling.affine3d.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 (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 ants.contrib.sampling.affine3d.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 (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 ants.contrib.sampling.affine3d.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 (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 ants.contrib.sampling.affine3d.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 (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 ants.contrib.sampling.affine3d.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 (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 ants.contrib.sampling.affine3d.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 (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 ants.contrib.sampling.affine3d.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 (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 ants.contrib.sampling.affine3d.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 (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)

ants.contrib.sampling.transforms module

Various data augmentation transforms for ANTsImage types

List of Transformations:

  • CastIntensity

  • BlurIntensity

  • NormalizeIntensity

  • RescaleIntensity

  • ShiftScaleIntensity

  • SigmoidIntensity

Todo

  • RotateImage

  • ShearImage

  • ScaleImage

  • DeformImage

  • PadImage

  • HistogramEqualizeIntensity

  • TruncateIntensity

  • SharpenIntensity

  • MorpholigicalIntensity
    • MD

    • ME

    • MO

    • MC

    • GD

    • GE

    • GO

    • GC

class ants.contrib.sampling.transforms.BlurIntensity(sigma, width)[source]

Bases: object

Transform for blurring the intensity of an ANTsImage using a Gaussian Filter

transform(X, y=None)[source]

Blur an image by applying a gaussian filter.

Parameters:
  • X (ANTsImage) – image to transform

  • y (ANTsImage (optional)) – another image to transform.

Example

>>> import ants
>>> blur = ants.contrib.BlurIntensity(2,3)
>>> img2d = ants.image_read(ants.get_data('r16'))
>>> img2d_b = blur.transform(img2d)
>>> ants.plot(img2d)
>>> ants.plot(img2d_b)
>>> img3d = ants.image_read(ants.get_data('mni'))
>>> img3d_b = blur.transform(img3d)
>>> ants.plot(img3d)
>>> ants.plot(img3d_b)
class ants.contrib.sampling.transforms.CastIntensity(pixeltype)[source]

Bases: object

Cast the pixeltype of an ANTsImage to a given type. This code uses the C++ ITK library directly, so it is fast.

NOTE: This offers a ~2.5x speedup over using img.clone(pixeltype):

Timings vs Cloning

>>> import ants
>>> import time
>>> caster = ants.contrib.CastIntensity('float')
>>> img = ants.image_read(ants.get_data('mni')).clone('unsigned int')
>>> s = time.time()
>>> for i in range(1000):
...     img_float = caster.transform(img)
>>> e = time.time()
>>> print(e - s) # 9.6s
>>> s = time.time()
>>> for i in range(1000):
...     img_float = img.clone('float')
>>> e = time.time()
>>> print(e - s) # 25.3s
transform(X, y=None)[source]

Transform an image by casting its type

Parameters:

Example

>>> import ants
>>> caster = ants.contrib.CastIntensity('float')
>>> img2d = ants.image_read(ants.get_data('r16')).clone('unsigned int')
>>> img2d_float = caster.transform(img2d)
>>> print(img2d.pixeltype, '- ', img2d_float.pixeltype)
>>> img3d = ants.image_read(ants.get_data('mni')).clone('unsigned int')
>>> img3d_float = caster.transform(img3d)
>>> print(img3d.pixeltype, ' - ' , img3d_float.pixeltype)
class ants.contrib.sampling.transforms.FlipImage(axis1, axis2)[source]

Bases: object

Transform an image by flipping two axes.

transform(X, y=None)[source]

Transform an image by applying a sigmoid function.

Parameters:
  • X (ANTsImage) – image to transform

  • y (ANTsImage (optional)) – another image to transform.

Example

>>> import ants
>>> flipper = ants.contrib.FlipImage(0,1)
>>> img2d = ants.image_read(ants.get_data('r16'))
>>> img2d_r = flipper.transform(img2d)
>>> ants.plot(img2d)
>>> ants.plot(img2d_r)
>>> flipper2 = ants.contrib.FlipImage(1,0)
>>> img2d = ants.image_read(ants.get_data('r16'))
>>> img2d_r = flipper2.transform(img2d)
>>> ants.plot(img2d)
>>> ants.plot(img2d_r)
class ants.contrib.sampling.transforms.LocallyBlurIntensity(conductance=1, iters=5)[source]

Bases: object

Blur an ANTsImage locally using a gradient anisotropic diffusion filter, thereby preserving the sharpeness of edges as best as possible.

transform(X, y=None)[source]

Locally blur an image by applying a gradient anisotropic diffusion filter.

Parameters:
  • X (ANTsImage) – image to transform

  • y (ANTsImage (optional)) – another image to transform.

Example

>>> import ants
>>> blur = ants.contrib.LocallyBlurIntensity(1,5)
>>> img2d = ants.image_read(ants.get_data('r16'))
>>> img2d_b = blur.transform(img2d)
>>> ants.plot(img2d)
>>> ants.plot(img2d_b)
>>> img3d = ants.image_read(ants.get_data('mni'))
>>> img3d_b = blur.transform(img3d)
>>> ants.plot(img3d)
>>> ants.plot(img3d_b)
class ants.contrib.sampling.transforms.MultiResolutionImage(levels=4, keep_shape=False)[source]

Bases: object

Generate a set of images at multiple resolutions from an original image

transform(X, y=None)[source]

Generate a set of multi-resolution ANTsImage types

Parameters:
  • X (ANTsImage) – image to transform

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

Example

>>> import ants
>>> multires = ants.contrib.MultiResolutionImage(levels=4)
>>> img = ants.image_read(ants.get_data('r16'))
>>> imgs = multires.transform(img)
class ants.contrib.sampling.transforms.NormalizeIntensity[source]

Bases: object

Normalize the intensity values of an ANTsImage to have zero mean and unit variance

NOTE: this transform is more-or-less the same in speed as an equivalent numpy+scikit-learn solution.

Timing vs Numpy+Scikit-Learn

>>> import ants
>>> import numpy as np
>>> from sklearn.preprocessing import StandardScaler
>>> import time
>>> img = ants.image_read(ants.get_data('mni'))
>>> arr = img.numpy().reshape(1,-1)
>>> normalizer = ants.contrib.NormalizeIntensity()
>>> normalizer2 = StandardScaler()
>>> s = time.time()
>>> for i in range(100):
...     img_scaled = normalizer.transform(img)
>>> e = time.time()
>>> print(e - s) # 3.3s
>>> s = time.time()
>>> for i in range(100):
...     arr_scaled = normalizer2.fit_transform(arr)
>>> e = time.time()
>>> print(e - s) # 3.5s
transform(X, y=None)[source]

Transform an image by normalizing its intensity values to have zero mean and unit variance.

Parameters:
  • X (ANTsImage) – image to transform

  • y (ANTsImage (optional)) – another image to transform.

Example

>>> import ants
>>> normalizer = ants.contrib.NormalizeIntensity()
>>> img2d = ants.image_read(ants.get_data('r16'))
>>> img2d_r = normalizer.transform(img2d)
>>> print(img2d.mean(), ',', img2d.std(), ' -> ', img2d_r.mean(), ',', img2d_r.std())
>>> img3d = ants.image_read(ants.get_data('mni'))
>>> img3d_r = normalizer.transform(img3d)
>>> print(img3d.mean(), ',' , img3d.std(), ',', ' -> ', img3d_r.mean(), ',' , img3d_r.std())
class ants.contrib.sampling.transforms.RescaleIntensity(min_val, max_val)[source]

Bases: object

Rescale the pixeltype of an ANTsImage linearly to be between a given minimum and maximum value. This code uses the C++ ITK library directly, so it is fast.

NOTE: this offered a ~5x speedup over using built-in arithmetic operations in ANTs. It is also more-or-less the same in speed as an equivalent numpy+scikit-learn solution.

Timing vs Built-in Operations

>>> import ants
>>> import time
>>> rescaler = ants.contrib.RescaleIntensity(0,1)
>>> img = ants.image_read(ants.get_data('mni'))
>>> s = time.time()
>>> for i in range(100):
...     img_float = rescaler.transform(img)
>>> e = time.time()
>>> print(e - s) # 2.8s
>>> s = time.time()
>>> for i in range(100):
...     maxval = img.max()
...     img_float = (img - maxval) / (maxval - img.min())
>>> e = time.time()
>>> print(e - s) # 13.9s

Timing vs Numpy+Scikit-Learn

>>> import ants
>>> import numpy as np
>>> from sklearn.preprocessing import MinMaxScaler
>>> import time
>>> img = ants.image_read(ants.get_data('mni'))
>>> arr = img.numpy().reshape(1,-1)
>>> rescaler = ants.contrib.RescaleIntensity(-1,1)
>>> rescaler2 = MinMaxScaler((-1,1)).fit(arr)
>>> s = time.time()
>>> for i in range(100):
...     img_scaled = rescaler.transform(img)
>>> e = time.time()
>>> print(e - s) # 2.8s
>>> s = time.time()
>>> for i in range(100):
...     arr_scaled = rescaler2.transform(arr)
>>> e = time.time()
>>> print(e - s) # 3s
transform(X, y=None)[source]

Transform an image by linearly rescaling its intensity to be between a minimum and maximum value

Parameters:
  • X (ANTsImage) – image to transform

  • y (ANTsImage (optional)) – another image to transform.

Example

>>> import ants
>>> rescaler = ants.contrib.RescaleIntensity(0,1)
>>> img2d = ants.image_read(ants.get_data('r16'))
>>> img2d_r = rescaler.transform(img2d)
>>> print(img2d.min(), ',', img2d.max(), ' -> ', img2d_r.min(), ',', img2d_r.max())
>>> img3d = ants.image_read(ants.get_data('mni'))
>>> img3d_r = rescaler.transform(img3d)
>>> print(img3d.min(), ',' , img3d.max(), ' -> ', img3d_r.min(), ',' , img3d_r.max())
class ants.contrib.sampling.transforms.ScaleImage(scale, reference=None, interp='linear')[source]

Bases: object

Scale an image in physical space. This function calls highly optimized ITK/C++ code.

transform(X, y=None)[source]

Example

>>> import ants
>>> scaler = ants.contrib.ScaleImage((1.2,1.2))
>>> img2d = ants.image_read(ants.get_data('r16'))
>>> img2d_r = scaler.transform(img2d)
>>> ants.plot(img2d, img2d_r)
>>> scaler = ants.contrib.ScaleImage((1.2,1.2,1.2))
>>> img3d = ants.image_read(ants.get_data('mni'))
>>> img3d_r = scaler.transform(img3d)
>>> ants.plot(img3d, img3d_r)
class ants.contrib.sampling.transforms.ShiftScaleIntensity(shift, scale)[source]

Bases: object

Shift and scale the intensity of an ANTsImage

transform(X, y=None)[source]

Transform an image by shifting and scaling its intensity values.

Parameters:
  • X (ANTsImage) – image to transform

  • y (ANTsImage (optional)) – another image to transform.

Example

>>> import ants
>>> shiftscaler = ants.contrib.ShiftScaleIntensity(10,2.)
>>> img2d = ants.image_read(ants.get_data('r16'))
>>> img2d_r = shiftscaler.transform(img2d)
>>> print(img2d.min(), ',', img2d.max(), ' -> ', img2d_r.min(), ',', img2d_r.max())
>>> img3d = ants.image_read(ants.get_data('mni'))
>>> img3d_r = shiftscaler.transform(img3d)
>>> print(img3d.min(), ',' , img3d.max(), ',', ' -> ', img3d_r.min(), ',' , img3d_r.max())
class ants.contrib.sampling.transforms.SigmoidIntensity(min_val, max_val, alpha, beta)[source]

Bases: object

Transform an image using a sigmoid function

transform(X, y=None)[source]

Transform an image by applying a sigmoid function.

Parameters:
  • X (ANTsImage) – image to transform

  • y (ANTsImage (optional)) – another image to transform.

Example

>>> import ants
>>> sigscaler = ants.contrib.SigmoidIntensity(0,1,1,1)
>>> img2d = ants.image_read(ants.get_data('r16'))
>>> img2d_r = sigscaler.transform(img2d)
>>> img3d = ants.image_read(ants.get_data('mni'))
>>> img3d_r = sigscaler.transform(img3d)
class ants.contrib.sampling.transforms.TranslateImage(translation, reference=None, interp='linear')[source]

Bases: object

Translate an image in physical space. This function calls highly optimized ITK/C++ code.

transform(X, y=None)[source]

Example

>>> import ants
>>> translater = ants.contrib.TranslateImage((40,0))
>>> img2d = ants.image_read(ants.get_data('r16'))
>>> img2d_r = translater.transform(img2d)
>>> ants.plot(img2d, img2d_r)
>>> translater = ants.contrib.TranslateImage((40,0,0))
>>> img3d = ants.image_read(ants.get_data('mni'))
>>> img3d_r = translater.transform(img3d)
>>> ants.plot(img3d, img3d_r, axis=2)

Module contents