简体   繁体   中英

How to create add gaussian noise on an image

I want to create a function to add gaussian noise to a single input that I will later use. I'm using the imageio module in Python.

def gaussian_noise(x, var):

I thought x is the tensor you want to add gaussian noise to, and var is the variance of gaussian noise.

Your question is vague, but you can add gaussian noise like this:

import torch

def gaussian_noise(x, var):
  return torch.normal(0, var, size=x.shape)

T = torch.ones(4, 5)
T += gaussian_noise(T, 0.1)
print(T)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM