Shortcuts

ElasticTransform

class torchvision.transforms.ElasticTransform(alpha=50.0, sigma=5.0, interpolation=InterpolationMode.BILINEAR, fill=0)[source]

Transform a tensor image with elastic transformations. Given alpha and sigma, it will generate displacement vectors for all pixels based on random offsets. Alpha controls the strength and sigma controls the smoothness of the displacements. The displacements are added to an identity grid and the resulting grid is used to grid_sample from the image.

Applications:

Randomly transforms the morphology of objects in images and produces a see-through-water-like effect.

Parameters:
  • alpha (float or sequence of python:floats) – Magnitude of displacements. Default is 50.0.

  • sigma (float or sequence of python:floats) – Smoothness of displacements. Default is 5.0.

  • interpolation (InterpolationMode) – Desired interpolation enum defined by torchvision.transforms.InterpolationMode. Default is InterpolationMode.BILINEAR. If input is Tensor, only InterpolationMode.NEAREST, InterpolationMode.BILINEAR are supported. The corresponding Pillow integer constants, e.g. PIL.Image.BILINEAR are accepted as well.

  • fill (sequence or number) – Pixel fill value for the area outside the transformed image. Default is 0. If given a number, the value is used for all bands respectively.

Examples using ElasticTransform:

Illustration of transforms

Illustration of transforms
forward(tensor: Tensor) Tensor[source]
Parameters:

tensor (PIL Image or Tensor) – Image to be transformed.

Returns:

Transformed image.

Return type:

PIL Image or Tensor

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources