I'm having an issue with an OpenCL image filter I've been trying to get working. I've written many of these before (Sobel Edge Detection, Auto Segmentation, and such), so I thought I knew how to do this, but the following code is giving me some really weird output:
//NoRedPixels.cl
__kernel void NoRedPixels(
__read_only image2d_t srcImg,
__write_only image2d_t dstImg,
sampler_t sampler,
int width, int height,
int threshold,
int colour,
int fill)
{
int2 imageCoordinate = (int2)(get_global_id(0), get_global_id(1));
if (imageCoordinate.x < width && imageCoordinate.y < height)
{
float4 pixel = read_imagef(srcImg, sampler, imageCoordinate);
float4 blue = (float4)(0.0f,0.0f,1.0f,1.0f);
if (1.0f - pixel.x <= 0.1f)
write_imagef(dstImg, imageCoordinate, blue);
else
write_imagef(dstImg, imageCoordinate, pixel);
}
}
So for testing, all I want to do is replace red pixels with blue ones, but this code will replace all matching pixels with WHITE ones. As far as I know, my formatting for blue is proper RGBA formatting for creating pure blue (I've done this before without issue).
I'm using PyOpenCL as my framework, and I've made sure to set the image channel order for both the source and destination images as RGBA. In addition, I've also made sure to convert the source image to RGBA format (using Python Imaging Library) if it was not already in that format before running the kernel on it.
I've gone back and looked at other kernels I've written, and the formatting is identical. What am I missing here that would cause it to write white pixels out instead of blue ones?