After reading the original picture as shown below, there will be a lot of noise point
Then we should use noise filtering process to deal with these points in the following ways:
1, mean filter
For a pixel, you can draw a box around it a convolution with the mean of the box instead of the pixel, is calculated as (121 + 75 + ... + 235) / 9
It is equivalent to a 3 × 3 convolution matrix, the value of each position is 1, and the convolution matrix multiply pixel matrix, the matrix is then divided by the size of
After filtering mean, as follows:
1 # Mean filtering 2 Blur = cv2.blur (IMG, (3,3))
We can see a lot of noise points less than the original image, but there are still some noise point
2, the filter block
There are two cases block the filter, if done normalization, and mean filtering on the same
1 # block filter (i.e., normalization, and mean the same filtering) 2 box1 = cv2.boxFilter (IMG, -1, (3,3), the normalize = True)
If not normalized, that is, all of the values together in a box convolution, not averaged, i.e., 121 + 235 + 75 + ...
Because the pixels in the range from 0 to 255, combined if more than this range, a white spot is displayed
1 # block filter (not normalized) 2 BOX2 = cv2.boxFilter (IMG, -1, (3,3), the normalize = False)
3, Gaussian
Convolution in the box, some pixels from the center pixel point away recently, so the relationship between it and the center pixel of the more recent, when averaged weight should be larger
For example in the case of 3 × 3, up and down on the center of the shorter distance, the four corners will be slightly longer distance
Gaussian filtering is based on averaging to each point on the added weight
1 #高斯滤波 2 gaussian=cv2.GaussianBlur(img,(5,5),1)
4、中值滤波
就是将卷积盒子中的像素点按顺序排成一列,取它的中间数,即中位数
24,75,78,104,113,121,154,204,235,中位数是113,就用113来代替中心像素点的值
1 #中值滤波 2 median=cv2.medianBlur(img,5)
可以看到,利用中值滤波处理后,噪音点基本没有了