Game Development Reference
In-Depth Information
__global__ void flog( const gpu_plm2<float4> st, float sigma,
gpu_plm2< float > 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 ;
float2 n = st_major_ev(st(ix, iy));
float2 nabs = fabs(n);
float ds = 1.0f / ((nabs.x > nabs.y)? nabs.x : nabs.y);
float2 uv = make_float2 (ix + 0.5f, iy + 0.5f);
float halfWidth = 5 * sigma;
float sigma2 = sigma * sigma;
float twoSigma2 = 2 * sigma2;
float sum = -sigma2 * tex2D (texL, ix + 0.5f, iy + 0.5f);
for ( float d = ds; d <= halfWidth; d += ds ) {
float k = (d*d - sigma2) * __expf( -d*d / twoSigma2 );
float2 o = d*n;
float c= tex2D (texL, uv.x - o.x, uv.y - o.y) +
tex2D (texL, uv.x + o.x, uv.y + o.y);
sum += k * c;
}
sum = sum / ( sqrtf (2*CUDART_PI_F) * sigma2 * sigma);
dst(ix, iy) = sum;
}
Listing 5.6. Implementation of the FLoG filter.
image converted to grayscale, let v = G σ i
L ,andlet x 0
be the current pixel;
then the convolution is computed by
z ( x 0 )= σ g
G σ g ( t ) v x 0 + ( x 0 ) d t,
where η ( x 0 ) denotes the major eigenvector. The implementation is shown in
Listing 5.6. Evaluation of the integral is performed using a constant step size that
has a unit size, along either the x -orthe y -axis (Figure 5.12), and using bilinear
dx
dy
dy
dx
2
1
dx
1 +
=
dy
dx
dx
dy
1
dy
dx
dy
2
1
dy
dx
1 +
=
1
(a)
(b)
Figure 5.12. Computation of a step vector that has unit size in either horizontal or
vertical directions. Two cases must be distinguished: (a) dx > dy and (b) dy > dx .
 
Search Nedrilad ::




Custom Search