Add Gaussian noise transformation
🚀 The feature
Add gaussian noise transformation in the functionalities of torchvision.transforms.
Motivation, pitch
Using Normalizing Flows, is good to add some light noise in the inputs. Right now I am using albumentation for this but, would be great to use it in the torchvision library
Alternatives
Albumentation has a gaussian noise implementation
Additional context
No response
cc @vfdev-5 @datumbox
Hi @mjack3 thanks for the request.
We do have GaussianBlur https://github.com/pytorch/vision/blob/main/torchvision/transforms/transforms.py#L1765
May I know what's the difference between gaussian blur and gaussian Noise? In case they are same feel free to use T.GaussianBlur
@oke-aditya maybe the correct link is https://albumentations.ai/docs/api_reference/augmentations/transforms/#albumentations.augmentations.transforms.GaussNoise
Apply gaussian noise to the input image
What do you think @vfdev-5 ? Is this useful to add to torchvision.transforms ?
Gaussian noise and Gaussian blur are different as I am showing below. As I said, Gaussian noise is used in several unsupervised learning methods

I think Salt and Pepper and Gaussian Noise are valid transforms to offer. I would probably be in favour to create them on the new API which is in progress. Wdyt?
Seems great, salt pepper noise and gaussian Noise and probably textBook transforms. Seems nice addition to new API.
A minimal workaround today could be the following (keeping in mind all limitations it could have):
from PIL import Image
import torch
import torchvision
img = Image.open("test-image.jpg")
from torchvision.transforms import Compose, PILToTensor, ToPILImage
# Tensor GN pipeline
def gauss_noise_tensor(img):
assert isinstance(img, torch.Tensor)
dtype = img.dtype
if not img.is_floating_point():
img = img.to(torch.float32)
sigma = 25.0
out = img + sigma * torch.randn_like(img)
if out.dtype != dtype:
out = out.to(dtype)
return out
t1 = Compose([
PILToTensor(),
gauss_noise_tensor,
# For visualization purposes
ToPILImage()
])
o1 = t1(img)
import matplotlib.pyplot as plt
%matplotlib inline
plt.figure(figsize=(14, 7))
plt.subplot(121)
plt.title("Pillow")
plt.imshow(img)
plt.subplot(122)
plt.title("Tensor GN")
plt.imshow(o1)

I agree that we could implement it and its variant in the transforms.
That will the job for now