Game Development Reference

In-Depth Information

__global__
void
grad_shock(
const
gpu_plm2<float4> st,

const
gpu_plm2<
float
> sign,

float
radius,

gpu_plm2<float4> dst )

{

const int
ix = blockDim.x * blockIdx.x + threadIdx.x;

const int
iy = blockDim.y * blockIdx.y + threadIdx.y;

if
(ix >= dst.w || iy >= dst.h)
return
;

minmax_impl_t mm(
make_float2
(ix + 0.5f, iy + 0.5f));

float2
n = st_major_ev(st(ix, iy));

float
s = sign(ix, iy);

if
(s < 0) {

mm.run<MAX_FLT>(n, radius);

}
else if
(s > 0) {

mm.run<MIN_FLT>(n, radius);

}

dst(ix, iy) =
tex2D
(texSRC, mm.p_.x, mm.p_.y);

}

Listing 5.7.
Implementation of the gradient-directed shock filter.

interpolation. Due to the unit step size, this results in a linear interpolation of

two neighboring pixels and allows for ecient implementation on GPUs using

texturing hardware.

The erosion and dilation operations are implemented as directional neighbor-

hood filters as well.

Let
f
denote the input image, and let
x
0

be the current

point, then the gradient-directed shock filter is defined as

⎧

⎨

min

x
∈
Λ
r
(
x
0
)

f
(
x
) f
z
(
x
0
)
>
+
τ
s
,

max

x
∈
Λ
r
(
x
0
)

f
(
x
) f
z
(
x
0
)
<

−

τ
s
,

⎩

f
(
x
0
)

otherwise
.

Determination of the minimum and maximum is performed based on the corre-

sponding gray values. The filter neighborhood Λ
r
is defined as the set of pixels

with a distance less than
r
from
x
0

defined

Again, a constant step size with a unit size in either horizontal or vertical direction

is used. Bilinear interpolation, however, is not appropriate for the computation

of the minimum or maximum; therefore, the two neighboring pixels are sampled

explicitly, using nearest-neighbor sampling. Through a small correction of the

sampling offset, the correct sampling of horizontal, vertical, and diagonal lines is

assured as well.

For the radius, typically
r
= 2 is used. The parameter
τ
s
controls the sen-

sitivity to noise and is typically set to
τ
s

intersecting the line

{

x
0
+
λη
(
x
0
)

}

∈

[0
,
0
.
01]. Since a scale-normalized

LoG is used,
τ
s
does not depend upon
σ
g
.

The threshold effectively prevents

Search Nedrilad ::

Custom Search