//高斯核Mat gaussian_kernal(int kernelRowSize,int kernelColSize,double sigma0) { float halfRowSize = (kernelRowSize-1)/ 2.0 ;float halfColSize = (kernelColSize-1)/ 2.0; Mat K(kernelRowSize, kernelColSize, CV_32FC1); //生成二维高斯核 double s2 = 2.0 * sigma0 * sigma0; for(float i = (-halfRowSize); i <= halfRowSize; i+=1) { int m = i + halfRowSize; for (float j = (-halfColSize); j <= halfColSize; j+=1) { int n = j + halfColSize; float v = exp(-(1.0*i*i + 1.0*j*j) / s2); K.ptr(m)[n] = v; } } Scalar all = sum(K); Mat gaussK; K.convertTo(gaussK, CV_32FC1, (1/all[0])); return gaussK; }
OpenCV二维高斯滤波核实现 matlab的fspecial函数
最新推荐文章于 2023-12-17 13:56:47 发布