Path to mathematics-python computing practice (16)-machine vision-filter denoising (neighborhood average method filtering)
#-*-Coding: UTF-8-*-# code: myhaspl@myhaspl.com # neighborhood filtering with a radius of 2 import cv2import numpy as npfn = "test3.jpg" myimg = cv2.imread (fn) img = cv2.cvtColor (myimg, cv2.COLOR _ BGR2GRAY) # Add salt and pepper noise param = 20 # grayscale range w = img. shape [1] h = img. shape [0] newimg = np. array (img) # noisecount = 100000for k in xrange (0, noisecount): xi = int (np. random. uniform (0, newimg. shape [1]) xj = int (np. random. uniform (0, newimg. shape [0]) newimg [xj, xi] = 255 # neighborhood average de-noise tmpimg [1: myh-1, 1: myw-1] = newimg [0: myh, 0: myw] # using the domain average method, set the radius to 2, and the impulse response function a = 1/8. 0 kernel = a * np. array ([[, 1], [, 1], [, 1]) ......
The above is the salt and pepper noise filtering.
All content of this blog is original, if reproduced please indicate the source http://blog.csdn.net/myhaspl/
<Strong? Http: www.bkjia.com kf ware vc "target =" _ blank "class =" keylink "> VcD48cD48aW1nIHNyYz0 = "http://www.2cto.com/uploadfile/Collfiles/20140720/20140720085851410.png" alt = "\"/>
It is processing Gaussian noise filtering, and the effect is indeed good.