Welcome to Rider Pi Robot repository
7. Median Filter
7. Median Filtering
7.1. Median Filtering
Median filtering: Image smoothing can eliminate salt and pepper noise. The basic idea is to traverse the image through the filter and take the median of the pixel value in each filter area as the new pixel value.
The algorithm idea is as follows:
(1) Input the image and convert it to grayscale;
(2) Add salt and pepper noise to the grayscale image
(3) Traverse the pixels and put the pixel values in the filter area into a one-dimensional array;
(4) Select and sort the one-dimensional array and assign the middle value to the filter center, that is, change the traversed original image pixel point to the median of the filter area;
(5) Output the image after median filtering
7.2 Actual effect display
Source code path:
/home/pi/Rider-pi_class/4.Open Source CV/D.Image_Enhancement/07_Median_Filter.ipynb
ximport cv2import numpy as npimport matplotlib.pyplot as pltimg = cv2.imread('yahboom.jpg',1)imgInfo = img.shapeheight = imgInfo[0]width = imgInfo[1]img = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)# cv2.imshow('src',img)dst = np.zeros((height,width,3),np.uint8)collect = np.zeros(9<