猿问

使用python在图像中插入白色高斯噪声

我试图搜索与 Matlab 函数(imnoise)相对应的 python 函数。我想使用高斯白噪声来增强图像。


高斯白噪声的 matlab 代码:


[I, map]=imread("img.png");

I=double(I)/255;

V=var(I(:)); %compute the image variance

J=imnoise(I, 'gaussian', 0, V/10); %insert gaussian white noise with mean zero and tenth of that variance


皈依舞
浏览 290回答 1
1回答

泛舟湖上清波郎朗

你可以使用 numpy 和 Pillow !from PIL import Imageimport numpy as np# Load the image into a numpy arrayI = Image.open(filename)I_array = np.array(im)# Calculate the variance for the image and the noiseM = 0V = np.var(im_array)noise = np.random.normal(mean, variance, I_array.shape)# Add the noise to the image numpy array and convert# everything back to a PIL image.I_array_noise = np.add(I_array, noise)J = Image.fromarray(I_array_noise)
随时随地看视频慕课网APP

相关分类

Python
我要回答