发布时间:2021-10-08 22:21:07编辑:run阅读(5637)
scipy ndimage模块提供了一个名为percentile_filter()的函数,它是中值滤波器的一个通用版本。
脉冲噪声图
from skimage.io import imread import matplotlib.pylab as pylab import numpy as np pylab.rcParams['font.sans-serif'] = ['KaiTi'] pylab.rcParams['axes.unicode_minus'] = False def plot_image(image, title=''): pylab.title(title, size=15) pylab.imshow(image) pylab.axis('off') lena = imread(r'D:\image_processing\image4\f.jpg') noise = np.random.random(lena.shape) lena[noise > 0.9] = 255 lena[noise < 0.1] = 0 plot_image(lena, '噪声图') pylab.show()
中值滤波器
from skimage.io import imread import matplotlib.pylab as pylab import numpy as np from scipy import signal, misc, ndimage pylab.rcParams['font.sans-serif'] = ['KaiTi'] pylab.rcParams['axes.unicode_minus'] = False def plot_image(image, title=''): pylab.title(title, size=15) pylab.imshow(image) pylab.axis('off') lena = imread(r'D:\image_processing\image4\f.jpg') noise = np.random.random(lena.shape) lena[noise > 0.9] = 255 lena[noise < 0.1] = 0 plot_image(lena, '噪声图') pylab.show() fig = pylab.figure(figsize=(20, 15)) i = 1 for p in range(25, 100, 25): for k in range(5, 25, 5): pylab.subplot(3, 4, i) filtered = ndimage.percentile_filter(lena, percentile=p, size=(k, k, 1)) plot_image(filtered, str(p) + ' 核尺寸为, ' + str(k) + 'x' + str(k)) i += 1 pylab.show()
运行上面代码,可以看到,在所有百分位滤波器中,核尺寸较小的中值滤波器(对应于第50百分位)在去除脉冲噪声方面的效果最好,而同时丢失的图像细节也极少。
下一篇: 没有了
47675
46116
37002
34563
29164
25824
24656
19793
19339
17831
5637°
6221°
5763°
5818°
6770°
5559°
5558°
6055°
6033°
7365°