简体   繁体   English

了解OpenCV图像平滑

[英]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 这个问题是关于本教程的: 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. 在该代码中,所有平滑方法都在循环内运行MAX_KERNEL_LENGTH次。 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. 在伪c ++代码中,计算看起来像这样。

 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. 提到为MAX_KERNEL_LENGTH的变量只是创建一个这样的内核的矩阵的最大大小。

The MAX_KERNEL_LENGTH is defined as a constant (31) in the code. MAX_KERNEL_LENGTH在代码中定义为常数(31)。 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. 它用于将内核大小从1x1更改为31x31,以显示本教程中使用的不同模糊算法中不同内核大小的影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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