05-27-2026 04:26 AM - edited 05-27-2026 04:32 AM
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
05-27-2026 04:39 AM - edited 05-27-2026 04:40 AM
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!
05-27-2026 07:53 AM
Try using this. Look for hues within a range.
05-28-2026 04:05 PM - edited 05-28-2026 04:06 PM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
05-29-2026 04:00 PM - edited 05-29-2026 04:39 PM
@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.
06-03-2026 08:56 AM - edited 06-03-2026 08:57 AM
> 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
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