Digital Image Processing (7) Mean Filtering

Topic: Filter an image using a mean filter.
The international standard test image Lena is used.
The 3*3 mean filter is defined as follows:
insert image description here
c++ code:

cv::Mat image = cv::imread("Lena.bmp");
    cv::Mat src(image.size(),CV_8UC1);
    cv::cvtColor(image, src, CV_BGR2GRAY);

    cv::Mat dst = src.clone();

    double v = 0;
    int r = 3;

    for (int row = 1; row < dst.rows-1; row++)
    {
    
    
        for (int col = 1; col < dst.cols-1; col++)
        {
    
    
            v = 0;
            for (int dy = -1; dy < r - 1; dy++)
            {
    
    
                for (int dx = -1; dx < r - 1; dx++)
                {
    
    
                    v = v + dst.at<uchar>(row + dy, col + dx);
                }
            }
            dst.at<uchar>(row, col) = uchar(v / (r*r));
        }
    }

The results show:
insert image description here
the characteristics of the average filter:
the calculation of the average will blur the edge information and feature information in the image, and many features will be lost, which will reduce the clarity of the scene and blur the picture. For Gaussian noise, when the length of the filter is large enough, there is a very good noise suppression effect.
Reference link: https://github.com/gzr2017/ImageProcessing100Wen/blob/master/Question_01_10/answers_cpp/answer_7.cpp

Guess you like

Origin blog.csdn.net/qq_41596730/article/details/126993289