lightly.transforms

The lightly.transforms package provides additional augmentations.

Contains implementations of Gaussian blur and random rotations which are not part of torchvisions transforms.

.gaussian_blur

Gaussian Blur

class lightly.transforms.gaussian_blur.GaussianBlur(kernel_size: float, prob: float = 0.5, scale: float = 0.2)

Implementation of random Gaussian blur.

Utilizes the built-in ImageFilter method from PIL to apply a Gaussian blur to the input image with a certain probability. The blur is further randomized as the kernel size is chosen randomly around a mean specified by the user.

kernel_size

Mean kernel size for the Gaussian blur.

prob

Probability with which the blur is applied.

scale

Fraction of the kernel size which is used for upper and lower limits of the randomized kernel size.

.rotation

Random Rotation

class lightly.transforms.rotation.RandomRotate(prob: float = 0.5, angle: int = 90)

Implementation of random rotation.

Randomly rotates an input image by a fixed angle. By default, we rotate the image by 90 degrees with a probability of 50%.

This augmentation can be very useful for rotation invariant images such as in medical imaging or satellite imaginary.

prob

Probability with which image is rotated.

angle

Angle by which the image is rotated. We recommend multiples of 90 to prevent rasterization artifacts. If you pick numbers like 90, 180, 270 the tensor will be rotated without introducing any artifacts.

.solarize

Solarization

class lightly.transforms.solarize.RandomSolarization(prob: float = 0.5, threshold: int = 128)

Implementation of random image Solarization.

Utilizes the integrated image operation solarize from Pillow. Solarization inverts all pixel values above a threshold (default: 128).

probability

Probability to apply the transformation

threshold

Threshold for solarization.