With the previousMean Filter
In view of the median filter is not very easy to continue. The mean filtering is performed on the average value of 3*3 pixels around the pixel, so the value is to find the value in the pixel of 3*3. Let's look at such a descriptive image (no picture, no truth)
Here we can clearly see that there are 6, 2, 4, 10 pixels, and then these pixel values in the middle are replaced by the median, that is, the median, of these pixels. To meet the requirements and the previous articleArticleCorresponding format, we will immediately enter the next unit to see the effect of smoothing and noise reduction!
After the first median filter
After the noise graph (5%) is filtered in the mean value:
The very impressive point can be seen here, it is obvious that the median filter is not only a smooth image, at the same time, the salt and pepper noise is removed (the pixels in the outermost circle of the image are not removed because I have not processed them from 0-width ). From the logic of the value here, when we perform the value operation, the white (255) and Black (0) are the maximum and minimum values, unless the surrounding colors are black or white, otherwise it will be removed, which is the biggest difference from the mean! Therefore, the effect is much better. In general, this median filter is an ideal choice to remove salt and pepper noise.
In the same way, I am still posting a pieceCode:
/** <Br/> ** method to remove noise from the specified upted image by median value <br/> * @ Param specified upted input grayscale binary array with specified upted info <br/> * @ Param smooth output data for smooth result, the memory need to be allocated outside of the function <br/> * @ Param width of the input grayscale image <br/> * @ Param height of the input grayscale image <br /> */<br/> void medianfilter (unsigned char * converted upted, unsigned char * smooth, int width, int height) <br/>{</P> <p> memcpy (smooth, upted, width * height * sizeof (unsigned char )); <br/> for (Int J = 1; j <peight-1; j ++) <br/>{< br/> for (INT I = 1; I <width-1; I ++) <br/>{< br/> int K = 0; <br/> unsigned char window [9]; <br/> for (int jj = J-1; JJ <j + 2; ++ JJ) <br/> for (int ii = I-1; II <I + 2; ++ II) <br/> window [k ++] = upted [JJ * width + II]; <br/> // order elements (only half of them) <br/> for (INT m = 0; m <5; ++ m) <br/> {<br/> int min = m; <br/> for (INT n = m + 1; n <9; ++ N) <br/> If (window [N] <window [Min]) <br/> min = N; <br/> // put found minimum element in its place <br/> unsigned char temp = Window [m]; <br/> window [m] = Window [Min]; <br/> window [Min] = temp; <br/>}< br/> smooth [J * width + I] = Window [4]; <br/>}< br/>}