source: OpenCLIterative3DDeconvolution/src/publication/sobel.cl @ 6961

Revision 6961, 818 bytes checked in by rlentz, 9 years ago (diff)
Line 
1__kernel void sobel( __global float* input,
2        __global float* output,
3     int width,
4     int height )
5
6    int x = get_global_id(0);
7    int y = get_global_id(1);
8    float p[9];
9    int offset = y * width + x;
10if( x < 1 || y < 1 || x > width - 2 || y > height - 2 )
11{
12  output[offset] = 0;
13}
14else
15{
16    p[0] = input[offset - width - 1] ;
17    p[1] = input[offset - width] ;
18    p[2] = input[offset - width + 1] ;
19    p[3] = input[offset - 1] ;
20    p[4] = input[offset] ;
21    p[5] = input[offset + 1] ;
22    p[6] = input[offset + width - 1] ;
23    p[7] = input[offset + width] ;
24    p[8] = input[offset + width + 1] ;
25
26    float sum1 = p[0] + 2*p[1] + p[2] - p[6] - 2*p[7] - p[8];  //GY
27    float sum2 = p[0] + 2*p[3] + p[6] - p[2] - 2*p[5] - p[8];  //GX
28   
29    output[offset] = sqrt(  sum1*sum1 + sum2*sum2 );
30}
31}
Note: See TracBrowser for help on using the repository browser.