我试图在应用低通滤波器后向图像添加白噪声。我知道如何在 matlab 中执行此操作,但不知道如何调用它才能在 python 中工作。
import matplotlib.pyplot as plt
import numpy as np
import scipy.misc
from scipy import ndimage
import Image
J = imnoise(im,'salt & pepper',0.02);
figure.imshow(J)
我还需要导入什么?还是有另一种增加噪音的方法?
请您参考如下方法:
scikit-image提供一个函数random_noise这类似于 MATLAB 中的 imnoise。
skimage.util.random_noise(image, mode='gaussian', seed=None, clip=True, **kwargs)
它支持以下模式:
‘gaussian’ Gaussian-distributed additive noise.
‘localvar’ Gaussian-distributed additive noise, with specified local variance at each point of image
‘poisson’ Poisson-distributed noise generated from the data.
‘salt’ Replaces random pixels with 1.
‘pepper’ Replaces random pixels with 0.
‘s&p’ Replaces random pixels with 0 or 1.
‘speckle’ Multiplicative noise using out = image + n*image, where n is uniform noise with specified mean & variance.
请注意,与 MATLAB 中的 imnoise 的一个区别是此函数的输出始终是浮点图像。
例如,如果输入图像是 uint8 灰度图像,它首先会被转换为 float,但输出图像不会被转换为与输入图像相同的类。
因此如果你关心图像的类,你应该自己转换输出,例如使用skimage.img_as_ubyte。
