float integrate_surface(__read_only image2d_t input,
const uint width,
const uint height,
const int col,
const int row,
const int halfWidth,
const int halfHeight,
const sampler_t sampler){
int top = row - halfHeight - 1;
int bottom = top + 2 * halfHeight + 1;
int left = col - halfWidth - 1;
int right = left + 2 * halfWidth + 1;
float A = read_imagef(input, sampler, (int2)( left, top )).x;
float B = read_imagef(input, sampler, (int2)( right, top )).x;
float C = read_imagef(input, sampler, (int2)( left, bottom )).x;
float D = read_imagef(input, sampler, (int2)( right, bottom )).x;
return D - B - C + A;
}
__kernel void compute(__read_only image2d_t input,
__global float * output,
const uint width,
const uint height,
const uint h,
const int offset,
const sampler_t sampler){
int c = get_global_id(0);
int r = get_global_id(1);
if (c>width-1 || r>height-1)
return;
int l = 2 * h + 1;
// Compute Lxx
float white_xx = integrate_surface(input, width, height, c, r, h+l, l-1, sampler);
float black_xx = integrate_surface(input, width, height, c, r, h, l-1, sampler);
float L_xx = white_xx - 3.f * black_xx;
// Compute Lyy
float white_yy = integrate_surface(input, width, height, c, r, l-1, h+l, sampler);
float black_yy = integrate_surface(input, width, height, c, r, l-1, h, sampler);
float L_yy = white_yy - 3.f * black_yy;
// Compute result
output[r*width+c] = L_xx * L_yy;
// output[r*width+c] = 0.f;
}