Convert Lux to RGB

  • Thread starter noknow
  • Start date
  • #1
5
1

Main Question or Discussion Point

I have an optical sensor that outputs 4 values in the following format: [ Red, Green, Blue, IR] where each value is in lux. I want to take this output and render a color on my pc. I'm not sure how to convert this into a regular RGB (0-255)/hexcolor value. Is there a good place to start? The data sheet I have on the device doesn't mention anything about a conversion. Many thanks.
 
Last edited:

Answers and Replies

  • #2
rbelli1
Gold Member
908
328
  • #4
sophiecentaur
Science Advisor
Gold Member
23,998
4,158
I have an optical sensor that outputs 4 values in the following format: [ Red, Green, Blue, IR] where each value is in lux. I want to take this output and render a color on my pc. I'm not sure how to convert this into a regular RGB (0-255)/hexcolor value. Is there a good place to start? The data sheet I have on the device doesn't mention anything about a conversion. Many thanks.
I'm not sure that the above link tells the whole story. It may relate to a particular piece of equipment. I would imagine the gains in the four channels of your equipment should take care of things, largely. Your PC will do the usual thing for displaying RGB signals. (0 - 255)
RGB analogue signals will depend on the sensitivity of the sensor. Once you have established (by measurement or from a spec sheet) the peak voltage that the sensor produces then your ADC input just needs to be scaled so that the peak value gives 256 on one of the channels. That will give you the most dynamic range without limiting / clipping.
Lux is a measure of the flux, weighted by the human spectral response curve so the three RGB signals would all be (roughly) equal for incident white light - depending on the colour temperature of the source. The ratios of your RGB readings will, presumably relate to the formula in that link, above.
I don't know about the IR value as we have no perception of those wavelengths. The IR values you get could vary a lot according to the actual spectrum of sources which could 'appear' the same and have equal RGB values. (I'm coming at this from the point of view of TV colourimetry so IR is not part of that.) To display IR as part of your PC image, you would need some false colour algorithm to shift all the colours in the blue direction and make room for IR to be displayed in the Reds. I found a lot of Google hits for False Colour infra red search terms. This could be unnecessary if you are just interested in the long wavelength of the spectrum - you could just feed your monitor with Ir, R , G signals instead of R G B, ignoring the B altogether. Worth trying perhaps; no programming or soldering involved.

PS Astrophotography links will be a rich source of ideas about false colour rendering.
 
  • #5
5
1
Spec sheet for the sensor


I'm not sure that the above link tells the whole story. It may relate to a particular piece of equipment. I would imagine the gains in the four channels of your equipment should take care of things, largely. Your PC will do the usual thing for displaying RGB signals. (0 - 255)
RGB analogue signals will depend on the sensitivity of the sensor. Once you have established (by measurement or from a spec sheet) the peak voltage that the sensor produces then your ADC input just needs to be scaled so that the peak value gives 256 on one of the channels. That will give you the most dynamic range without limiting / clipping.
Lux is a measure of the flux, weighted by the human spectral response curve so the three RGB signals would all be (roughly) equal for incident white light - depending on the colour temperature of the source. The ratios of your RGB readings will, presumably relate to the formula in that link, above.
I don't know about the IR value as we have no perception of those wavelengths. The IR values you get could vary a lot according to the actual spectrum of sources which could 'appear' the same and have equal RGB values. (I'm coming at this from the point of view of TV colourimetry so IR is not part of that.) To display IR as part of your PC image, you would need some false colour algorithm to shift all the colours in the blue direction and make room for IR to be displayed in the Reds. I found a lot of Google hits for False Colour infra red search terms. This could be unnecessary if you are just interested in the long wavelength of the spectrum - you could just feed your monitor with Ir, R , G signals instead of R G B, ignoring the B altogether. Worth trying perhaps; no programming or soldering involved.

PS Astrophotography links will be a rich source of ideas about false colour rendering.
So my understanding is that lux takes into account the human response/perception of color so I don't need any correction (gamma?) for that. I see that the spec sheet includes min/max counts for RGB but I don't see any max voltage value.
 
  • #6
sophiecentaur
Science Advisor
Gold Member
23,998
4,158
lux takes into account the human response/perception of color
Yes. It does its best to achieve that for an 'average' observer. I think including a nonlinear factor would not be possible - can you think of how it could be? You need to read more deeply into what is meant by luminosity. The eye is adaptive so how could you chase that?
but I don't see any max voltage value.
The block diagram implies that the sensor outputs go directly to the ADC. Which Voltage are you referring to?
 
  • #7
5
1
Yes. It does its best to achieve that for an 'average' observer. I think including a nonlinear factor would not be possible - can you think of how it could be? You need to read more deeply into what is meant by luminosity. The eye is adaptive so how could you chase that?


The block diagram implies that the sensor outputs go directly to the ADC. Which Voltage are you referring to?
I will read up on luminosity more, I'm a little lost. I'm not used to viewing data sheets at all and my background is not in EE.
But I'm trying to figure out the next steps given the data sheet.
 
  • #8
sophiecentaur
Science Advisor
Gold Member
23,998
4,158
It depends on what you want to achieve. Do you want to produce 'four colour images' with a three colour display' to include IR?
I am still not clear which voltage you refer to as the device appears to produce four digital (8 bit Edit - 16bit) output signals.
 
Last edited:
  • #9
sophiecentaur
Science Advisor
Gold Member
23,998
4,158
Having looked at the data sheet I am a bit clearer about what the device does. It will give you RGB values for a particular displayed colour according to (or near) the formula in the link higher up. Afaics, you want to know the RGB values needed to produce a specified colour on the scree in terms of the YUV values?
Formulae for this and the reverse process can be found here. Could that be what you actually need to know?
 
  • #10
5
1
Yes. It does its best to achieve that for an 'average' observer. I think including a nonlinear factor would not be possible - can you think of how it could be? You need to read more deeply into what is meant by luminosity. The eye is adaptive so how could you chase that?


The block diagram implies that the sensor outputs go directly to the ADC. Which Voltage are you referring to?
Thank
Having looked at the data sheet I am a bit clearer about what the device does. It will give you RGB values for a particular displayed colour according to (or near) the formula in the link higher up. Afaics, you want to know the RGB values needed to produce a specified colour on the scree in terms of the YUV values?
Formulae for this and the reverse process can be found here. Could that be what you actually need to know?
I feel like we're getting closer. I want to display the lux values onto my personal site. So it will have to conform to css standards. https://developer.mozilla.org/en-US/docs/Glossary/RGB
RGB are a 3 separate 8 bit integers. Is that enough information?
 
  • #11
5
1
Is it as simple as converting a 16 bit value into an 8 bit value?
 
  • #12
DaveC426913
Gold Member
18,556
2,027
Thank
I feel like we're getting closer. I want to display the lux values onto my personal site. So it will have to conform to css standards. https://developer.mozilla.org/en-US/docs/Glossary/RGB
Are you planning to do this manually?

Because I am pretty sure you can find JS plugin libraries that will directly convert YUV to RGB for you on-the-fly.

Here's a Stack Overflow question that should get you started:
https://stackoverflow.com/questions/21264648/javascript-convert-yuv-to-rgb

Alternately, just Google 'JavaScript convert YUV to RGB'.
 

Related Threads for: Convert Lux to RGB

  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
6
Views
2K
Replies
2
Views
810
Replies
5
Views
3K
  • Last Post
Replies
6
Views
8K
  • Last Post
Replies
4
Views
2K
Top