简体   繁体   English

如何从浮点数4得知像素颜色是否为黑色

[英]how to know if the pixel color is black from a float 4

I ask my question how to know pixel color using t_sampler in jocl in a different way I want to konw if a pixel is black or white knowing that I am using t_sampler in my kernel 我问我的问题, 如何在jocl使用t_sampler以不同的方式了解像素颜色?我想知道像素是黑色还是白色时知道我在内核中使用t_sampler

const sampler_t smp = CLK_NORMALIZED_COORDS_FALSE | //Natural coordinates
                      CLK_ADDRESS_CLAMP | //Clamp to zeros
                      CLK_FILTER_NEAREST; //Don't interpolate

Then I used 然后我用

int2 coord = (int2)(get_global_id(0), get_global_id(1));
    float4 pixel = read_imageui(input, smp, coord);

My question is: how to use the value pixel to know the color of the concerned pixel? 我的问题是:如何使用值像素来了解相关像素的颜色?

I am stuck from few days and I tried many solutions to solve this problem, If you need any clarifications I will respond. 几天以来我一直处于停滞状态,并且尝试了许多解决方案来解决此问题,如果您需要任何澄清,我会答复。 Here is my kernel code 这是我的内核代码

const sampler_t smp = CLK_NORMALIZED_COORDS_FALSE | //Natural coordinates
                      CLK_ADDRESS_CLAMP | //Clamp to zeros
                      CLK_FILTER_NEAREST; //Don't interpolate
__kernel void basic(__read_only image2d_t input,__global float *result) 
{

   int gidX = get_global_id(0);
    int gidY = get_global_id(1);

int2 coord = (int2)(get_global_id(0), get_global_id(1));

int2 posIn = {gidX, gidY};

      float4 pixel = read_imagef(input, smp, posIn);
if ((pixel.x==0.0) && (pixel.y==0.0) && (pixel.z==0.0) ){

result[gidX]=1;
}  else result[gidX]=0;
    }

Read the pixel using read_imagef (I recommend it instead of read_imageui , depending on the image format, especially since in your example you are assigning to a float4 variable; check the specification for which is appropriate for each image format). 使用read_imagef读取像素(我建议使用它而不是read_imageui ,具体取决于图像格式,尤其是在您的示例中,您要分配给float4变量;请检查适用于每种图像格式的规范)。 The float4 components returned can then be checked. 然后可以检查返回的float4组件。 pixel.x is the red, pixel.y is the green, pixel.z is the blue, and pixel.w is the alpha (1.0f if the source format doesn't have alpha). pixel.x是红色, pixel.y是绿色, pixel.z是蓝色, pixel.w是alpha(如果源格式没有alpha, pixel.w 1.0f)。 To check for black (as you ask in the subject of your question), just check that .x and .y and .z are all 0.0. 要检查黑色(如您在问题主题中所问的),只需检查.x和.y和.z均为0.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM