我是Python的新手,我想在灰度图像中添加高斯噪声.我已经将原始图像转换为灰度以测试一些形态学方法去噪(使用PyMorph)但我不知道如何添加噪声.
sas*_*cha 10
您没有提供有关代码当前状态以及您想要的确切类型噪声的大量信息.但通常会使用基于numpy的图像,然后只是根据某些分布添加一些随机样本.
例:
import numpy as np
# ...
img = ... # numpy-array of shape (N, M); dtype=np.uint8
# ...
mean = 0.0 # some constant
std = 1.0 # some constant (standard deviation)
noisy_img = img + np.random.normal(mean, std, img.shape)
noisy_img_clipped = np.clip(noisy_img, 0, 255) # we might get out of bounds due to noise
Run Code Online (Sandbox Code Playgroud)