程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python3 SciPy ndimage smoothing

編輯:Python

stay python3 Of scipy ndimage The module provides a module called percentile_filter() Function of , It is a general version of median filter .

Impulse noise diagram

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, ' Noise map ')
pylab.show()

Median filter

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, ' Noise map ')
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) + '  The nuclear size is , ' + str(k) + 'x' + str(k))
        i += 1
pylab.show()

After running the code above , We can see , In all percentile filters , Median filter with smaller core size ( Corresponding to the first 50 Percentile ) It has the best effect in removing impulse noise , At the same time, there are very few missing image details .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved