File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
algorithms/image-processing Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Generate Gaussian filter
2
+
3
+ #include < cmath>
4
+ #include < iomanip>
5
+ #include < iostream>
6
+ using namespace std ;
7
+
8
+ // Function to create Gaussian filter
9
+ void FilterCreation (double GKernel[][5 ])
10
+ {
11
+ // intialising standard deviation to 1.0
12
+ double sigma = 1.0 ;
13
+ double r, s = 2.0 * sigma * sigma;
14
+
15
+ // sum is for normalization
16
+ double sum = 0.0 ;
17
+
18
+ // generating 5x5 kernel
19
+ for (int x = -2 ; x <= 2 ; x++) {
20
+ for (int y = -2 ; y <= 2 ; y++) {
21
+ r = sqrt (x * x + y * y);
22
+ GKernel[x + 2 ][y + 2 ] = (exp (-(r * r) / s)) / (M_PI * s);
23
+ sum += GKernel[x + 2 ][y + 2 ];
24
+ }
25
+ }
26
+
27
+ // normalising the Kernel
28
+ for (int i = 0 ; i < 5 ; ++i)
29
+ for (int j = 0 ; j < 5 ; ++j)
30
+ GKernel[i][j] /= sum;
31
+ }
32
+
33
+ int main ()
34
+ {
35
+ double GKernel[5 ][5 ];
36
+ FilterCreation (GKernel);
37
+
38
+ for (int i = 0 ; i < 5 ; ++i) {
39
+ for (int j = 0 ; j < 5 ; ++j)
40
+ cout << GKernel[i][j] << " \t " ;
41
+ cout << endl;
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments