Comparison of the effects of opencv median filter and low-pass filter on salt and pepper noise processing
Effect: we can see from the comparison that the median filter retains the boundary information code of the image:
Void showimage (const STD: string & STR, const CV: mat & image) {namedwindow (STR, cv_window_autosize); imshow (STR, image );} mat salt (const CV: mat & image, int N) {mat result = image. clone (); For (INT I = 0; I <n; ++ I) {int ROW = rand () % result. rows; int Col = rand () % result. cols; result. at <vec3b> (row, col) [0] = 255; result. at <vec3b> (row, col) [1] = 255; result. at <vec3b> (row, col) [2] = 255;} return result;} int _ tmain (INT argc, _ tchar * argv []) {mat image = imread ("boldt.jpg"); showimage ("image", image); MAT saltimage = salt (image, 500); showimage ("saltimage", saltimage ); mat medianimage, blurimage; blur (saltimage, blurimage, size (5, 5); showimage ("blurimage", blurimage); medianblur (saltimage, medianimage, 5 ); showimage ("medianimage", medianimage); waitkey (0); Return 0 ;}