Hello,

I’m learning OpenCL (I come from the GLSL world) and I’m playing with normalized image coordinates (this is the way I am used, so I would like know how they work in OpenCL) but I’m having unpleasant side effects.

In my CL kernel, I’m appliyng a simple gaussian kernel. I wasn’t realized the problem using small convolutions, but when I tried (just to play with) with big convolutions (21x21 and so) I realized out that there happens some breaking bands that didn’t happened using non-normalized coordinates.

I’m totally lost about this. I revised all code many times and with more eyes. I dont know if the error is in the normalization code, in the convolution code, in the images samplers… so I would appreciate any clue about this.

Here is the kernel:

```
__kernel void filter(__read_only image2d_t imageIn, __write_only image2d_t imageOut, sampler_t sampler, __global float* filter, int sizeSampler)
{
int2 ids = (int2)(get_global_id(0),
get_global_id(1));
int2 imageSize = (int2)(get_image_width(imageIn),
get_image_height(imageIn));
if (ids.x >= imageSize.x || ids.y >= imageSize.y)
{
return;
}
// Normalize coordinates
float2 coords = (float2)((float)ids.x / (imageSize.x - 1),
(float)ids.y / (imageSize.y - 1));
// Compute the right pixel size
float2 pixelSize = (float2)(1.0f / imageSize.x,
1.0f / imageSize.y);
// Compute the numer of steps I will have to move around the convolution
float position = sizeSampler / 2;
// Initial position of the convolution (left bottom)
float2 startPos = {coords.x - position * pixelSize.x,
coords.y - position * pixelSize.y};
// End position of the convolution (right top)
float2 endPos = {coords.x + position * pixelSize.x,
coords.y + position * pixelSize.y};
// Filter image
int weight = 0;
float4 pixel = (float4)(0.0f, 0.0f, 0.0f, 0.0f);
for(float2 finalCoords = startPos; finalCoords.y <= endPos.y; finalCoords.y += pixelSize.y)
{
for (finalCoords.x = startPos.x; finalCoords.x <= endPos.x; finalCoords.x += pixelSize.x)
{
pixel += read_imagef(imageIn, sampler, finalCoords) * filter[weight++];
}
}
float4 pixelOut = (float4)(pixel.xyz, 1.0f);
write_imagef (imageOut, ids, pixelOut);
}
```

Also, here is the image, to reveal the defects (you can see the breaks and image duplication (because the mix caused by the application of the convolution) at the left part of the image: