Image coordinates Stupid question...

Hi!

When I use read_imagef to read a 2D image, does the coordinates start at 0 or 1? (not normalized, using a linear sampler) I can’t seem to find this info anywhere…

Best regards,
Madsen

The center of the first pixel is at 0.5f.

When I use image object, I use the coordinates as if they start from 0 and it seems to work.
So I guess they start at the address 0 like normal arrays.

Try copying one image directly to another with the sampler set to linear interpolation, and place them over each other in a graphics editing tool. Then you’ll find out for sure whether it’s 0, 0.5 or 1. :)

possible to get an example with images coord ? :sweat:

here an example of kernel that copy an image2D in another image 2D. The global size of the call should be 2 dimensional and equal to the image dimension of course :)

__kernel void CopyImage(__read_only image2d_t imageIn,__write_only image2d_t imageOut)

{

  const sampler_t sampler=CLK_NORMALIZED_COORDS_FALSE|CLK_ADDRESS_CLAMP|CLK_FI

LTER_NEAREST;

  int gid0 = get_global_id(0);

  int gid1 = get_global_id(1);

  uint4 pixel;

  pixel=read_imageui(imageIn,sampler,(int2)(gid0,gid1));

  write_imageui (imageOut,(int2)(gid0,gid1),pixel);

}

The guy that started the thread asked about read_imagef though, floating point access, not integer index access. :)

Possible to do :

float4 pixel[j*128+i] = read_imagef(imageIn,sampler,(int2)(i,j));

pixel[coord].x == value ?