1 #define POW2
(a) ((a) * (a))
2 kernel void bilateral_filter
(global float4
*in
,
7 int gidx
= get_global_id
(0);
8 int gidy
= get_global_id
(1);
9 int n_radius
= ceil
(radius);
10 int dst_width
= get_global_size
(0);
11 int src_width
= dst_width
+ n_radius
* 2;
15 in
[(gidy + n_radius
) * src_width
+ gidx
+ n_radius
];
16 float4 accumulated
= 0.0f
;
19 float diff_map
, gaussian_weight
, weight
;
21 for
(v = -n_radius
;v <= n_radius; ++v)
23 for
(u = -n_radius
;u <= n_radius; ++u)
25 i
= gidx
+ n_radius
+ u
;
26 j
= gidy
+ n_radius
+ v
;
28 int gid1d
= i
+ j
* src_width
;
32 - ( POW2(center_pix.x - tempf.x)
33 + POW2(center_pix.y - tempf.y)
34 + POW2(center_pix.z - tempf.z))
38 exp( - 0.5f * (POW2(u) + POW2(v)) / radius);
40 weight = diff_map * gaussian_weight;
42 accumulated += tempf * weight;
46 out[gidx + gidy * dst_width] = accumulated / count;