1: /*******************Compute Gradient and assign them to bin Images ******/
2: __global__ void Compute_GradientBin(float*O_data,float*Bin_Img)
3: {
4:
5:
6: unsigned int tid_x = threadIdx.x + __umul24(blockIdx.x,blockDim.x);
7: unsigned int tid_y = threadIdx.y + __umul24(blockIdx.y,blockDim.y);
8:
9: float angle;
10: float Gradx,Grady;
11:
12: ///////////////////////////////////////////////Access thhe image/////////////////////////////////
13: //#if Texture REading////////////////////////////////////TExture Memory
14: if(tid_x < Img_Attr.Image_width&&tid_y < Img_Attr.Image_height)
15: {
16:
17: if(tid_x == 0 || tid_x == Img_Attr.Image_width - 1 )
18: Gradx = 0.0f;
19: else
20: Gradx = (tex2D(Image_tex, tid_x + 1,tid_y) - tex2D(Image_tex, tid_x - 1,tid_y));
21: //+ tex2D(Image_tex, tid_x + 1,tid_y - 1 ) - tex2D(Image_tex, tid_x - 1,tid_y - 1)
22: //+ tex2D(Image_tex, tid_x + 1,tid_y + 1) - tex2D(Image_tex, tid_x - 1,tid_y + 1) ;
23: if (tid_y == 0|| tid_y == Img_Attr. Image_height - 1)
24: Grady = 0.0f;
25: else
26: Grady = (tex2D(Image_tex, tid_x ,tid_y + 1) - tex2D(Image_tex, tid_x,tid_y - 1)) ;
27: //+ tex2D(Image_tex, tid_x - 1,tid_y + 1 ) - tex2D(Image_tex, tid_x - 1,tid_y - 1)
28: //+ tex2D(Image_tex, tid_x + 1,tid_y + 1) - tex2D(Image_tex, tid_x + 1,tid_y - 1) ;
29:
30: ///////////////////////////////////////////////////////////////////////////////////////////////
31:
32:
33: /////////////////////////////Angle of the Gradient/////////////////
34:
35: if(Gradx != 0)
36: {angle = atan(Grady/Gradx)/3.14159f >= 0.0f ? atan(Grady/Gradx)/3.14159f : atan(Grady/Gradx)/3.14159f + 1.0f ;
37: if(Gradx < 0.0f && angle == 0.0f)
38: angle = 1.0f;
39: }
40: else
41: angle = 0.5f;//Though Condition Gradx == 0&&Grady == 0 exsits , it does not matter, cos its magnitude will be zero, which would affect Feature
42:
43: //Plain Output
44: O_data[tid_x + tid_y*Img_Attr.Image_width] = 0.5*(sqrtf(Grady*Grady + Gradx*Gradx));
45:
46: ///////////////////Bins
47: angle = angle*K;
48: //////////////////////////////////Bin Gradient Images
49: for(int Bin_id = 0; Bin_id < K;Bin_id++)
50: {
51: Bin_Img[tid_x + tid_y*Img_Attr.Image_width + Bin_id*Img_Attr.Image_size] = 0.0f;
52: if(angle <= (float)Bin_id + 1.0f&&angle >= (float)Bin_id)
53: Bin_Img[tid_x + tid_y*Img_Attr.Image_width + Bin_id*Img_Attr.Image_size] = 0.5*sqrtf(Gradx*Gradx + Grady*Grady);
54: }
55: }
56:
57: }