LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

test if a color is within a range

hello! I'm working on test script where I have to verify if "OK = green", "KO = orange", "Error = red" and so on...

What I do at present, and the simplest way is to know the RGB code of the expected color and do a comparison.

 

However, in order to prevent the test to be modified because possible small color changes during the program life, I would like to know if it's possible to test within a pre-defined color range?

 

-I consider a range as: triplet of RGB colors with variations representing more or less brightness/shadowness/greyness

-I notice that the colorbox is a concatenation of 3 hexadecimal values representing RGB each.

-when approaching white, black or grey, those 3 colors values approach to each other until being equal.

 

Can someone help me about this? is this possible/easy/complicated? can I find some program already doing this in internet?

 

thanks

Pierre FCentum TNS, Grenoble
Certified LabVIEW Associated Developer
0 Kudos
Message 1 of 6
(732 Views)

Hi Pierre,

 


@Pierre_F wrote:

However, in order to prevent the test to be modified because possible small color changes during the program life, I would like to know if it's possible to test within a pre-defined color range?


I recommend to convert the RGB color into the HSV representation: now you can easily compare the H (hue) for a small range to determine the color…

 


@Pierre_F wrote:

I notice that the colorbox is a concatenation of 3 hexadecimal values representing RGB each.


No, the colorbox has an U32 representation and the uppermost byte also has a meaning.

Read the LabVIEW help, like for the ColorToRGB function!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 6
(711 Views)

Try using this.  Look for hues within a range.

0 Kudos
Message 3 of 6
(672 Views)

I bet the HSB method is better.  But in the past when I needed to do this I would convert the color into RGB, then into a 3 coordinate plane, then get the distance from one color to the other.

 

If the distance from one color to the other is less than some value, I consider it the same.  Be sure and use the Color to RGB function as mentioned.

Message 4 of 6
(605 Views)

@Pierre_F wrote:

hello! I'm working on test script where I have to verify if "OK = green", "KO = orange", "Error = red" and so on...

What I do at present, and the simplest way is to know the RGB code of the expected color and do a comparison.

 

However, in order to prevent the test to be modified because possible small color changes during the program life, I would like to know if it's possible to test within a pre-defined color range?

 

 

thanks


You have received excellent advice on how to implement a solution based on your exact question using the approach you suggested. 

 

Now, would you like some advice on how to do it a better way?

 

I highlighted a few key fragments in bold text.  It sounds to me like you have defined requirements for a strict type def.ctl.  A U32 Ring of <Error=ff0000, ...  OK=0000FF> would work wonders to prevent follow on developers from messing up your fine code without universally applying the color scheme and fouling up all your result calculations.  

 

I used to load my Ring <[Strings, Values]> with the String array of <Error, Pass, Fail, Skipped, Aborted, Untested>.  This let me grab the results<> and do fun things with the String index. e.g. Inrange and Coerce 0<=Result<=2 no coercion would be all tested, Array product 0 (at least 1 Error) 1 (all Pass) else Fail, Skipped, Aborted, Untested found.  Fun stuff when you want Results more useful than a Boolean. IIRC I used red, green, yellow, blue, gray & white.


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 6
(558 Views)

> However, in order to prevent the test to be modified because possible small color changes during the program life, I would like to know if it's possible to test within a pre-defined color range?

 

a very simplistic color range using R:G:B ratios

e.g. if something is considered "redish", R:G and R:B is probably > 1

alexderjuengere_0-1780493703570.png

 

I don't recommend the approach shown above 😉

but I recomment the approach hoovah described in Message 4

use the euclidian distance (also known as  L2-norm or metric...) directly to identify if to rgb pixels are similiar!

 

While the HSV (Hue, Saturation, Value) channels align well with human intuition, the conversion from RGB is merely a coordinate transformation. Because it is a bijective (one-to-one) mapping, it preserves the exact same underlying information and does not inherently improve the statistical separability between any two data points

 

and moreover, I hate those color wheels...another approach would be to convert to YCbCr, which I prefer for no particular reason

 

 

 

 

Spoiler

 

 

 

 

 

 

0 Kudos
Message 6 of 6
(478 Views)