Hi Guys,

I am new to CUDA. I am trying to implement Hough Transform for line detection in CUDA. I use this piece of code in Mathematica 8. I do get an output but it’s pretty weird, random bright spots instead of waves(curves) that is expected I guess. I know there are a couple of implementations available in this forum but those appear too complicated to me given that the algorithm is pretty much simple. Right now I am not looking to implement a optimized version. I just wan’t it to be as simple as possible and work i.e give correct results. Here is my kernel. Note I haven’t added code for threshold checking.

HoughTransform =

"**global** void hough_line(unsigned char * in, unsigned char * out, int *outint, mint outsize, mint threshold, mint width, mint height,float arraySines, float arrayCosines )
{
mint xIndex = threadIdx.x + blockIdx.xblockDim.x;
mint yIndex = threadIdx.y + blockIdx.yblockDim.y;
mint index = xIndex + yIndex*width;

mint i;

float rho = 0;

```
if (xIndex < width && yIndex < height)
{
for ( i = 0 ;i < 36;i++)
{
rho = xIndex * arrayCosines[i] +
yIndex * arraySines[i];
index = (i * 5.0) + rho * 180;
if(index < outsize)
atomicAdd(&outint[index],1);
}
}
__syncthreads();
for( i = 0; i < outsize; i++) // Had to do this as atomicAdd doesn't support unsigned char*
{
out[i] = outint[i];
}
}";
```

Sorry if my implementation seems pretty naive and if I have made nay obvious mistakes. I am trying to learn. Thanks.