Skip to content

Spatial transforms

spatial_transforms #

InPlaneRotate dataclass #

InPlaneRotate(angle: float, interpolation: str = 'linear')

Bases: imgtools.transforms.spatial_transforms.SpatialTransform

InPlaneRotate operation class.

A callable class that rotates an image on a plane.

Parameters:

Name Type Description Default

angle #

float

The angle of rotation.

required

interpolation #

str

The interpolation method to use. Valid options are: - "linear" for bi/trilinear interpolation (default) - "nearest" for nearest neighbour interpolation - "bspline" for order-3 b-spline interpolation

'linear'

Methods:

Name Description
supports_reference

Return whether this transform supports reference images.

name property #

name: str

Return the name of the transform class for logging and debugging.

Returns:

Type Description
str

The name of the transform class.

supports_reference #

supports_reference() -> bool

Return whether this transform supports reference images.

Returns:

Type Description
bool

False by default. Subclasses should override this method

Source code in src/imgtools/transforms/spatial_transforms.py
def supports_reference(self) -> bool:
    """Return whether this transform supports reference images.

    Returns
    -------
    bool
        False by default. Subclasses should override this method
    """
    return False

Resample dataclass #

Resample(
    spacing: float | typing.Sequence[float] | numpy.ndarray,
    interpolation: str = "linear",
    anti_alias: bool = True,
    anti_alias_sigma: float | None = None,
    transform: SimpleITK.Transform | None = None,
    output_size: list[float] | None = None,
)

Bases: imgtools.transforms.spatial_transforms.SpatialTransform

Resample operation class.

A callable class that resamples image to a given spacing, optionally applying a transformation.

Parameters:

Name Type Description Default

spacing #

float | typing.Sequence[float] | numpy.ndarray

The new image spacing. If float, assumes the same spacing in all directions. Alternatively, a sequence of floats can be passed to specify spacing along each dimension. Passing 0 at any position will keep the original spacing along that dimension (useful for in-plane resampling).

required

interpolation #

str

The interpolation method to use. Valid options are: - "linear" for bi/trilinear interpolation (default) - "nearest" for nearest neighbour interpolation - "bspline" for order-3 b-spline interpolation

'linear'

anti_alias #

bool

Whether to smooth the image with a Gaussian kernel before resampling. Only used when downsampling, i.e. when spacing < image.GetSpacing(). This should be used to avoid aliasing artifacts.

True

anti_alias_sigma #

float | None

The standard deviation of the Gaussian kernel used for anti-aliasing.

None

transform #

SimpleITK.Transform | None

Transform to apply to input coordinates when resampling. If None, defaults to identity transformation.

None

output_size #

list[float] | None

Size of the output image. If None, it is computed to preserve the whole extent of the input image.

None

Methods:

Name Description
supports_reference

Return whether this transform supports reference images.

name property #

name: str

Return the name of the transform class for logging and debugging.

Returns:

Type Description
str

The name of the transform class.

supports_reference #

supports_reference() -> bool

Return whether this transform supports reference images.

Returns:

Type Description
bool

False by default. Subclasses should override this method

Return whether this transform supports reference images.

Returns:

Type Description
bool

Always True for spatial transforms.

Source code in src/imgtools/transforms/spatial_transforms.py
def supports_reference(self) -> bool:
    """Return whether this transform supports reference images.

    Returns
    -------
    bool
        Always True for spatial transforms.
    """
    return True

Resize dataclass #

Resize(
    size: int | list[int] | numpy.ndarray,
    interpolation: str = "linear",
    anti_alias: bool = True,
    anti_alias_sigma: float | None = None,
)

Bases: imgtools.transforms.spatial_transforms.SpatialTransform

Resize operation class.

A callable class that resizes image to a given size by resampling coordinates.

Parameters:

Name Type Description Default

size #

int | list[int] | numpy.ndarray

The new image size. If float, assumes the same size in all directions. Alternatively, a sequence of floats can be passed to specify size along each dimension. Passing 0 at any position will keep the original size along that dimension.

required

interpolation #

str

The interpolation method to use. Valid options are: - "linear" for bi/trilinear interpolation (default) - "nearest" for nearest neighbour interpolation - "bspline" for order-3 b-spline interpolation

'linear'

anti_alias #

bool

Whether to smooth the image with a Gaussian kernel before resampling. Only used when downsampling, i.e. when size < image.GetSize(). This should be used to avoid aliasing artifacts.

True

anti_alias_sigma #

float | None

The standard deviation of the Gaussian kernel used for anti-aliasing.

None

Methods:

Name Description
supports_reference

Return whether this transform supports reference images.

name property #

name: str

Return the name of the transform class for logging and debugging.

Returns:

Type Description
str

The name of the transform class.

supports_reference #

supports_reference() -> bool

Return whether this transform supports reference images.

Returns:

Type Description
bool

False by default. Subclasses should override this method

Source code in src/imgtools/transforms/spatial_transforms.py
def supports_reference(self) -> bool:
    """Return whether this transform supports reference images.

    Returns
    -------
    bool
        False by default. Subclasses should override this method
    """
    return False

Rotate dataclass #

Rotate(
    rotation_centre: list[int],
    angles: float | list[float],
    interpolation: str = "linear",
)

Bases: imgtools.transforms.spatial_transforms.SpatialTransform

Rotate operation class.

A callable class that rotates an image around a given centre.

Parameters:

Name Type Description Default

rotation_centre #

list[int]

The centre of rotation in image coordinates.

required

angles #

float | list[float]

The angles of rotation around x, y and z axes.

required

interpolation #

str

The interpolation method to use. Valid options are: - "linear" for bi/trilinear interpolation (default) - "nearest" for nearest neighbour interpolation - "bspline" for order-3 b-spline interpolation

'linear'

Methods:

Name Description
supports_reference

Return whether this transform supports reference images.

name property #

name: str

Return the name of the transform class for logging and debugging.

Returns:

Type Description
str

The name of the transform class.

supports_reference #

supports_reference() -> bool

Return whether this transform supports reference images.

Returns:

Type Description
bool

False by default. Subclasses should override this method

Source code in src/imgtools/transforms/spatial_transforms.py
def supports_reference(self) -> bool:
    """Return whether this transform supports reference images.

    Returns
    -------
    bool
        False by default. Subclasses should override this method
    """
    return False

SpatialTransform #

Bases: imgtools.transforms.base_transform.BaseTransform

Base class for spatial transforms.

Spatial transforms modify the spatial properties of an image, such as spacing, size, or orientation.

All spatial transforms support an optional reference image parameter in their call method.

Examples:

>>> # This is an abstract base class and cannot be instantiated directly.
>>> # Use one of its subclasses like Resample, Resize, etc.

Methods:

Name Description
supports_reference

Return whether this transform supports reference images.

name property #

name: str

Return the name of the transform class for logging and debugging.

Returns:

Type Description
str

The name of the transform class.

supports_reference #

supports_reference() -> bool

Return whether this transform supports reference images.

Returns:

Type Description
bool

False by default. Subclasses should override this method

Source code in src/imgtools/transforms/spatial_transforms.py
def supports_reference(self) -> bool:
    """Return whether this transform supports reference images.

    Returns
    -------
    bool
        False by default. Subclasses should override this method
    """
    return False

Zoom dataclass #

Zoom(
    scale_factor: float | list[float],
    interpolation: str = "linear",
    anti_alias: bool = True,
    anti_alias_sigma: float | None = None,
)

Bases: imgtools.transforms.spatial_transforms.SpatialTransform

Zoom operation class.

A callable class that rescales image, preserving its spatial extent.

The rescaled image will have the same spatial extent (size) but will be rescaled by scale_factor in each dimension. Alternatively, a separate scale factor for each dimension can be specified by passing a sequence of floats.

Parameters:

Name Type Description Default

scale_factor #

float | list[float]

If float, each dimension will be scaled by that factor. If tuple, each dimension will be scaled by the corresponding element.

required

interpolation #

str

The interpolation method to use. Valid options are: - "linear" for bi/trilinear interpolation (default) - "nearest" for nearest neighbour interpolation - "bspline" for order-3 b-spline interpolation

'linear'

anti_alias #

bool

Whether to smooth the image with a Gaussian kernel before resampling. Only used when downsampling, i.e. when size < image.GetSize(). This should be used to avoid aliasing artifacts.

True

anti_alias_sigma #

float | None

The standard deviation of the Gaussian kernel used for anti-aliasing.

None

Methods:

Name Description
supports_reference

Return whether this transform supports reference images.

name property #

name: str

Return the name of the transform class for logging and debugging.

Returns:

Type Description
str

The name of the transform class.

supports_reference #

supports_reference() -> bool

Return whether this transform supports reference images.

Returns:

Type Description
bool

False by default. Subclasses should override this method

Source code in src/imgtools/transforms/spatial_transforms.py
def supports_reference(self) -> bool:
    """Return whether this transform supports reference images.

    Returns
    -------
    bool
        False by default. Subclasses should override this method
    """
    return False