Hi I am trying to implement a sobel filter using Shared memory, but am getting a black output image. I have tried tweaking the code but it still doesnt give the output. Following is the code snippet:
#define tilewidth 14;
#define blockwidth 16;
global void d_SobelShared(unsigned char org,unsigned char result, int width, int height, const int restrict Gx, const int restrict Gy ){
int tx = threadIdx.x;
int ty = threadIdx.y;
int maskRadius=maskWidth/2;
__shared__ char img_ds[blockwidth][blockwidth];
int rowO = blockIdx.y*tilewidth+ty;
int colO = blockIdx.x*tilewidth+tx;
int rowI = rowO-maskRadius;
int colI = colO-maskRadius;
if( (rowI>=0) && (colI>=0) && (rowI<height) && (colI<width))
img_ds[ty][tx] = org[rowI*width+colI];
else
img_ds[ty][tx] = 0;
__syncthreads();
float opX=0,opY=0;
int sum=0,i=0,j=0;
if(ty<tilewidth && tx<tilewidth)
{
for( i=0;i<maskWidth;i++){
for( j=0;j<maskWidth;j++){
opX=opX+img_ds[i+ty][j+tx]*Gx [(i+maskRadius)*maskWidth+(j+maskRadius)];
opY=opY+img_ds[i+ty][j+tx]*Gy [(i+maskRadius)*maskWidth+(j+maskRadius)];
}
}
sum = abs(opX) + abs(opY) ;
if ( sum > 255) sum = 255;
if ( sum < 0) sum = 0;
}
__syncthreads();
if(tx<tilewidth && ty<tilewidth && rowO<height && colO<width)
{
result[rowO*width+colO]=sum;
}
}
Any help is greatly appreciated…
Thanks