简体   繁体   中英

Understanding OpenCV image smoothing

This question is about this tutorial http://docs.opencv.org/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.html#smoothing

In that code, all the smoothing methods are running inside a loop for MAX_KERNEL_LENGTH times. What is this kernel?

To calculate a smoothing for example an average is calculated for the closest pixels. Which and how many pixels that are given by this kernel. The kernel also contains information about weighting of the pixels.

The kernel is most often represented as a matrix (and in this case also) which is centered at each pixel that is the average is calculated for. The calculating looks like this in pseudo c++ code.

 for(int i=0;i<src.rows;i++){
     for (int j=0;j<src.cols;j++){
         dst[i][j]=0;
         for(int kernel_i=0;i<kernel.rows;i++){
             for (int kernel_j=0;j<kernel.cols;j++){
                  dst[i][j]+=
                      src[i-kernel.rows+kernel_i][j-kernel.cols+kernel_j]*
                      kernel[kernel_i][kernel_j];
             }
         }
     }
 }

The variable mentioned as MAX_KERNEL_LENGTH is simply the biggest size of the matrix creating one such kernel.

The MAX_KERNEL_LENGTH is defined as a constant (31) in the code. It is used to change the kernel size from 1x1 to 31x31 to show the effect of different kernel sizes in different blurring algorithms used in the tutorial.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM