LION.utils.image_transforms¶
Image transforms in plain torch.
gaussian_blur and rotate give the same results as
torchvision.transforms.functional’s (checked in pytests/test_utils.py),
which LION used before, without the torchvision dependency. Both work on any
number of leading dimensions, on any device, and are differentiable.
random_crop, random_flip_rotate and random_erasing are
GaussianDenoiserSolver’s augmentations (crop and erasing: kornia’s
RandomCrop and RandomErasing before, with the same defaults), on
batches (B, C, H, W). They draw from
torch’s random number generator on the CPU, so LION.utils.rng.seeded
makes them the same every time.
Functions
|
Gaussian blur of |
|
Normalised 1D Gaussian kernel of odd size |
|
A |
|
Each image of the batch |
Each image of the batch |
|
|
Images |
- LION.utils.image_transforms.gaussian_blur(x, kernel_size, sigma, dims=(-2, -1))[source]¶
Gaussian blur of
xalongdims, with reflected borders: a tensor of any shape, e.g. images (B, C, H, W) or sinograms (B, C, angles, detectors). Returns the blurred tensor, with the shape and dtype ofx.kernel_size: the odd kernel size, one for alldimsor one each;sigma: the standard deviation in pixels, likewise;dims: the dimensions to blur along (the last two, an image’s, by default;(-1,)blurs along the last only).
- LION.utils.image_transforms.gaussian_kernel1d(kernel_size, sigma, dtype=None, device=None)[source]¶
Normalised 1D Gaussian kernel of odd size
kernel_sizeand standard deviationsigma(in pixels), sampled at the pixel centres.
- LION.utils.image_transforms.random_crop(x, size)[source]¶
A
size(h, w) crop of each image of the batchx(B, C, H, W), at a random place in each image.
- LION.utils.image_transforms.random_erasing(x, p=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0.0)[source]¶
Each image of the batch
x(B, C, H, W), with probabilityp, with a random rectangle set tovalue: its area a fraction of the image’s drawn uniformly fromscale, its aspect ratio (height / width) drawn log-uniformly fromratio(up to 10 draws for one that fits, as in torchvision’sRandomErasing). Returns a new tensor.
- LION.utils.image_transforms.random_flip_rotate(x)[source]¶
Each image of the batch
x(B, C, H, W) flipped and rotated by a random one of the 8 symmetries of the square (rotations by multiples of 90 degrees, with or without a flip), as denoisers are trained (e.g. KAIR’saugment_img). Images that aren’t square get one of the 4 symmetries that keep their shape.