使用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

您可以使用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)

相关内容

  • 没有找到相关文章

最新更新