__global__ void kernel_medianR( short *output, int i_dim, int j_dim, int r) { // absolute coordinates of the center pixel int j = __mul24(blockIdx.x,blockDim.x) + threadIdx.x ; int i = __mul24(blockIdx.y,blockDim.y) + threadIdx.y ; short cpt, ic, jc ; short histogram[256] ; // 8 bit image // zeroing histogram data for (ic =0; ic<256; ic++) histogram[ ic ]=0 ; // histogram filling for(ic=i-r; ic<=i+r; ic++ ) for(jc=j-r; jc<=j+r; jc++) histogram[ tex2D(tex_img_ins, jc, ic) ]++ ; // histogram parsing cpt = 0 ; for(ic=0; ic<256; ic++) { cpt += histogram[ ic ] ; // selection of 50% percentile if ( cpt > ((2*r+1)*(2*r+1))>>1 ) break ; } output[ __mul24(i, j_dim) +j ] = ic ; }