使用 python 在图像中插入白高斯噪声
insert white gaussian nois in images using python
我试图搜索 python 对应于 Matlab 函数(imnoise)的函数。我想使用高斯白噪声增强图像。
高斯白噪声的 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
你可以为此使用 numpy 和 Pillow!
from PIL import Image
import numpy as np
# Load the image into a numpy array
I = Image.open(filename)
I_array = np.array(im)
# Calculate the variance for the image and the noise
M = 0
V = 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)
我试图搜索 python 对应于 Matlab 函数(imnoise)的函数。我想使用高斯白噪声增强图像。
高斯白噪声的 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
你可以为此使用 numpy 和 Pillow!
from PIL import Image
import numpy as np
# Load the image into a numpy array
I = Image.open(filename)
I_array = np.array(im)
# Calculate the variance for the image and the noise
M = 0
V = 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)