From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert the light wavelength into the color?

Hi all,
I need to show in the ColorBox the color of the light with some wavelength in nanometers. In other words the user should specify for example the 550nm wavelength and get the "green" color box.

I need a VI wich looks like transform function
light wavelength (nm) -> RGB

Thank you.

Oleg Chutko.
0 Kudos
Message 1 of 8
(6,014 Views)
Oleg,
This is a tricky question. However, here is a VI that should work in LabVIEW 4.1 and newer versions. I hope this helps.
/Mikael Garcia
Message 2 of 8
(6,014 Views)
Here is the reference I used for my solution:
http://www.integra.co.jp/eng/support/faq2_main.htm#usage28

/Mikael
0 Kudos
Message 3 of 8
(6,014 Views)
Here is the color spectrum generated by this VI (380-775 nm).
/Mikael
0 Kudos
Message 5 of 8
(6,014 Views)
"Oleg" wrote in message
news:5065000000080000007D4A0000-1021771306000@exchange.ni.com...
> Hi all,
> I need to show in the ColorBox the color of the light with some
> wavelength in nanometers. In other words the user should specify for
> example the 550nm wavelength and get the "green" color box.
>
> I need a VI wich looks like transform function
> light wavelength (nm) -> RGB

You will only be able to approximate the colors since the colors on the
monitor are not the same kind of colors as light mixtures. Notice that to
get violet they mix red and blue. If you mix red and blue light you don't
get violet, but if you mix red and blue paint you do.

So that being said I would say that you could do this in sections, see how
it comes out and then adju
st to taste. I know from my laser days that 632
is red and 488 is blue. 560 is probably as green as it gets. If the color
Xnm is between 560 and 632 then interpolate:
R=255(x-560)/(632-560)
G=255-R
B=0
Anything past 632 up to the limit of the eye (about 700) is pure red. Do
the same thing for green to blue. Violet is different since labview has red
to the right of violet but really that is a lie. Figure that the limit of
the eye (about 400nm I think) is pure violet.
B=255(x-312)/(488-312)
R=255-B
G=0
And stop when you get to 400.
0 Kudos
Message 4 of 8
(6,014 Views)
the problem of spectra to RGB is fairly complex. There are algorithms to convert spectra to XYZ and Lab color space coordinate that depend upon observer and illuminent settings. once you have XYZ, there is another transform with approximations to get to RGB.

I have included two lookup tables for spectra to RGB using Observer=IEC 1931 and Illuminant=D50. I do not remember where the coefficients for XYZ to RGB came from. One lookup table is more saturated that the other. Maybe this is good enough for your application.

The tables cover 380 to 780 nm every 5 nm.
Stu
Stu
0 Kudos
Message 6 of 8
(6,014 Views)
Stu,
can you save your VI with 6.0. version? I use 6.01 so I can't open VIs made with 6.1.

Thanks.
0 Kudos
Message 7 of 8
(6,014 Views)
attached is 6.0 version. BTW I like Mikael Garcia's answer as well. while mine might be technically more correct, his might meet your needs better.
Stu
Stu
0 Kudos
Message 8 of 8
(6,014 Views)