Bilinear interpolation on uchar image

Hello,

I would like to be able to use bilinear interpolation on my kernel. So I use this example:

cudaChannelFormatDesc  desc = cudaCreateChannelDesc<unsigned char>();
    checkCudaErrors(cudaBindTexture2D(0,&Image_Gray,u8_GrayImage_Device, &desc, icols , irows, icols));

It seems that the outpout ot the statement: tex2D(Image_Gray,v.x,v.y); is in int format, there is no interpolation.

How can I do the bilinear interpolation with u_int8_t data?

One cannot tell much from the snippet you posted. Consider posting a minimal, complete, self-contained repro code others can build and run. If I had to guess, you may not pass in texture coordinates correctly, or you may have incorrectly set up the texture attributes.

Note that the middle of each texel has an offset of 0.5 in both dimensions (e.g. the texel at 0,0 has its center at 0.5, 0.5). I am mentioning this because it’s a frequent mistake.

Thank you for the answer. Here is how I define my texture:

texture<unsigned char, 2,cudaReadModeElementType> Image_Gray;
......
        cudaChannelFormatDesc  desc = cudaCreateChannelDesc<unsigned char>();
        checkCudaErrors(cudaBindTexture2D(0,&Image_Gray,u8_GrayImage_Device, &desc, icols , irows,icols));

and in my kernel

__global void myKernel()
{
.................
float f_Val = tex2D(Image_Gray,x0,y0);

}

Edit: In fact you right, my coordinate was for example 0.5, 1.5, … I didn’t know that the center pixel was moved.

So If my image’s size is (w,h) my exact pixel coordinate was (0.5,0.5) to (w+0.5,h+0.5)?