高斯滤波 广泛应用于图像处理领域。它用于降低图像的噪声。在本文中,我们将生成一个二维高斯核。二维高斯核遵循下面给定的高斯分布。 式中,y是沿垂直轴与原点的距离,x是沿水平轴与原点的距离,σ是标准偏差。
null
C++实现
C++
// C++ program to generate Gaussian filter #include <cmath> #include <iomanip> #include <iostream> using namespace std; // Function to create Gaussian filter void FilterCreation( double GKernel[][5]) { // initialising standard deviation to 1.0 double sigma = 1.0; double r, s = 2.0 * sigma * sigma; // sum is for normalization double sum = 0.0; // generating 5x5 kernel for ( int x = -2; x <= 2; x++) { for ( int y = -2; y <= 2; y++) { r = sqrt (x * x + y * y); GKernel[x + 2][y + 2] = ( exp (-(r * r) / s)) / (M_PI * s); sum += GKernel[x + 2][y + 2]; } } // normalising the Kernel for ( int i = 0; i < 5; ++i) for ( int j = 0; j < 5; ++j) GKernel[i][j] /= sum; } // Driver program to test above function int main() { double GKernel[5][5]; FilterCreation(GKernel); for ( int i = 0; i < 5; ++i) { for ( int j = 0; j < 5; ++j) cout << GKernel[i][j] << " " ; cout << endl; } } |
输出:
0.00296902 0.0133062 0.0219382 0.0133062 0.00296902 0.0133062 0.0596343 0.0983203 0.0596343 0.0133062 0.0219382 0.0983203 0.162103 0.0983203 0.0219382 0.0133062 0.0596343 0.0983203 0.0596343 0.0133062 0.00296902 0.0133062 0.0219382 0.0133062 0.00296902
参考资料: https://en.wikipedia.org/wiki/Gaussian_filter 本文由 严酷的阿加瓦尔 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 写极客。组织 或者把你的文章寄去评论-team@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。 如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END