ElasticTransformation#

class deeptrack.optical.augmentations.ElasticTransformation(alpha: float | Callable[[...], float] = 20, sigma: float | Callable[[...], float] = 2, ignore_last_dim: bool | Callable[[...], bool] = True, order: int | Callable[[...], int] = 3, cval: float | Callable[[...], float] = 0, mode: str | Callable[[...], str] = 'constant', **kwargs)#

Bases: Augmentation

Apply elastic distortions to images.

This augmentation generates a random displacement field that locally warps the input image. The displacement field is created by sampling random noise and smoothing it with a Gaussian kernel. The parameters alpha and sigma control the strength and smoothness of the distortion field respectively.

Parameters#

alpha: PropertyLike[float], optional

Strength of the displacement field. Defaults to 20.

sigma: PropertyLike[float], optional

Standard deviation of the Gaussian kernel used to smooth the displacement field. Defaults to 2.

ignore_last_dim: PropertyLike[bool], optional

If `True`(default), the last dimension is assumed to represent channels and the same displacement field is applied to all channels.

order: PropertyLike[int], optional
Interpolation order used when resampling the image.
  • 0: Nearest-neighbor

  • 1: Bi-linear

  • 2: Bi-quadratic

  • 3: Bi-cubic (default)

  • 4: Bi-quartic

  • 5: Bi-quintic

cval: PropertyLike[float], optional

Constant value used when mode=”constant”. Defaults to 0.

mode: PropertyLike[str], optional

Boundary mode used when sampling outside the image domain. Matches scipy.ndimage.map_coordinates. Defaults to “constant”.

Methods#

get_numpy(image, **kwargs) -> np.ndarray

Applies the elastic transformation to a NumPy array.

get_torch(image, **kwargs) -> torch.Tensor

Applies the elastic transformation to a PyTorch tensor.

Notes#

This augmentation does not update “position” metadata. It should not be used if labels depend on spatial coordinates derived from the image.

Examples#

>>> import deeptrack as dt
>>> particle = dt.Ellipse()
>>> optics = dt.Fluorescence()
>>> elastic = dt.ElasticTransformation(alpha=30, sigma=3)
>>> image = optics(particle) >> elastic
>>> image.plot();