opnecv日記_GaussianBlur函數——高斯濾波 中文解釋參數含義

 
函數原型:
    void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT);
 
參數詳解以下:
    src,輸入圖像,即源圖像,填Mat類的對象便可。它能夠是單獨的任意通道數的圖片,但須要注意,圖片深度應該爲CV_8U,CV_16U, CV_16S, CV_32F 以及 CV_64F之一。
    dst,即目標圖像,須要和源圖片有同樣的尺寸和類型。好比能夠用Mat::Clone,以源圖片爲模板,來初始化獲得如假包換的目標圖。
    ksize,高斯內核的大小。其中ksize.width和ksize.height能夠不一樣,但他們都必須爲正數和奇數(並不能理解)。或者,它們能夠是零的,它們都是由sigma計算而來。
    sigmaX,表示高斯核函數在X方向的的標準誤差。
    sigmaY,表示高斯核函數在Y方向的的標準誤差。若sigmaY爲零,就將它設爲sigmaX,若是sigmaX和sigmaY都是0,那麼就由ksize.width和ksize.height計算出來。
    爲告終果的正確性着想,最好是把第三個參數Size,第四個參數sigmaX和第五個參數sigmaY所有指定到。
    borderType,用於推斷圖像外部像素的某種邊界模式。注意它有默認值BORDER_DEFAULT。
 
ps:
    高斯核函數:本身找找看,其實看上去就是普通的正態分佈函數形式。
    我猜ksize是模糊半徑的意思,水平方向和豎直方向的半徑不同,須要指定。
    標準誤差就是標準誤差……
 
英文:
Parameters:
    src – input image; the image can have any number of channels, which are processed independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
    dst – output image of the same size and type as src.
    ksize – Gaussian kernel size. ksize.width and ksize.height can differ but they both must be positive and odd. Or, they can be zero’s and then they are computed from sigma* .
    sigmaX – Gaussian kernel standard deviation in X direction.
    sigmaY – Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height , respectively (see getGaussianKernel() for details); to fully control the result regardless of possible future modifications of all this semantics, it is recommended to specify all of ksize, sigmaX, and sigmaY.
    borderType – pixel extrapolation method (see borderInterpolate() for details).
 
Demo:
#include "cv.h"
#include "highgui.h"
using namespace cv;
 
int main(int argc, char** argv) {
    Mat img, gray, edges;
    img = imread(argv[1]);
    cvtColor(img, gray, CV_BGR2GRAY);
    GaussianBlur(gray, gray, Size(13, 13), 2, 2);
    imshow("gray", gray);
    waitKey(0);
    return 0;
}
 
運行方法:
> g++ demo.cpp -o demo `pkg-config --cflags --libs opencv`
> ./demo 1.png
 
結果:
當ksize:(5, 5) -> (9, 9) -> (13, 13)時,
 
opencv <wbr>GaussianBlur函數——高斯濾波 <wbr>中文解釋參數含義

opencv <wbr>GaussianBlur函數——高斯濾波 <wbr>中文解釋參數含義

opencv <wbr>GaussianBlur函數——高斯濾波 <wbr>中文解釋參數含義

opencv <wbr>GaussianBlur函數——高斯濾波 <wbr>中文解釋參數含義
後二者差異已經很小了。

當sigmaX, sigmaY由(1, 1) -> (2, 2) -> (3, 3)時,
opencv <wbr>GaussianBlur函數——高斯濾波 <wbr>中文解釋參數含義

opencv <wbr>GaussianBlur函數——高斯濾波 <wbr>中文解釋參數含義

opencv <wbr>GaussianBlur函數——高斯濾波 <wbr>中文解釋參數含義

變化會明顯不少~
相關文章
相關標籤/搜索