MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / gaussianKernel

Function gaussianKernel

src/api/c/gaussian_kernel.cpp:36–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35template<typename T>
36Array<T> gaussianKernel(const int rows, const int cols, const double sigma_r,
37 const double sigma_c) {
38 const dim4 odims = dim4(rows, cols);
39 double sigma = 0;
40
41 Array<T> tmp = createValueArray<T>(odims, scalar<T>(0));
42 Array<T> half = createValueArray<T>(odims, 0.5);
43 Array<T> zero = createValueArray<T>(odims, scalar<T>(0));
44
45 if (cols > 1) {
46 Array<T> wt = range<T>(dim4(cols, rows), 0);
47 Array<T> w = transpose<T>(wt, false);
48
49 Array<T> c = createValueArray<T>(
50 odims, scalar<T>(static_cast<double>(cols - 1) / 2.0));
51 w = arithOp<T, af_sub_t>(w, c, odims);
52
53 sigma = sigma_c > 0 ? sigma_c : 0.25 * cols;
54 Array<T> sig = createValueArray<T>(odims, sigma);
55 w = arithOp<T, af_div_t>(w, sig, odims);
56
57 w = arithOp<T, af_mul_t>(w, w, odims);
58 tmp = arithOp<T, af_add_t>(w, tmp, odims);
59 }
60
61 if (rows > 1) {
62 Array<T> w = range<T>(dim4(rows, cols), 0);
63
64 Array<T> r = createValueArray<T>(
65 odims, scalar<T>(static_cast<double>(rows - 1) / 2.0));
66 w = arithOp<T, af_sub_t>(w, r, odims);
67
68 sigma = sigma_r > 0 ? sigma_r : 0.25 * rows;
69 Array<T> sig = createValueArray<T>(odims, sigma);
70
71 w = arithOp<T, af_div_t>(w, sig, odims);
72 w = arithOp<T, af_mul_t>(w, w, odims);
73 tmp = arithOp<T, af_add_t>(w, tmp, odims);
74 }
75
76 tmp = arithOp<T, af_mul_t>(half, tmp, odims);
77 tmp = arithOp<T, af_sub_t>(zero, tmp, odims);
78 tmp = unaryOp<T, af_exp_t>(tmp);
79
80 // Use this instead of (2 * pi * sig^2);
81 // This ensures the window adds up to 1
82 T norm_factor = getScalar<T>(reduce_all<af_add_t, T, T>(tmp));
83
84 Array<T> norm = createValueArray(odims, norm_factor);
85 Array<T> res = arithOp<T, af_div_t>(tmp, norm, odims);
86
87 return res;
88}
89
90af_err af_gaussian_kernel(af_array *out, const int rows, const int cols,
91 const double sigma_r, const double sigma_c) {

Callers 13

gaussianKernelTestCPPFunction · 0.50
TYPED_TESTFunction · 0.50
harris_demoFunction · 0.50
mainFunction · 0.50
usmFunction · 0.50
mainFunction · 0.50
blurFunction · 0.50
morphing_demoFunction · 0.50
DifferenceOfGaussianFunction · 0.50
gaussianblurFunction · 0.50
sobelFilterFunction · 0.50
mainFunction · 0.50

Calls 2

dim4Class · 0.50
createValueArrayFunction · 0.50

Tested by

no test coverage detected