how to convert light spectral / intensity to RGB value?
59 views (last 30 days)
Show older comments
Awal Mandong
on 30 Nov 2020
Commented: Bjorn Gustavsson
on 8 Jan 2021
dear all,
how do we convert light spectral / intensity to RGB value?
below is two spectral example., and i expect to have them having two different RGB value.
thanks
regards
0 Comments
Accepted Answer
Bjorn Gustavsson
on 30 Nov 2020
Edited: Bjorn Gustavsson
on 30 Nov 2020
Well I assume that you want to convert the envelope of the coloured region into a single RGB-tripplet. In your particular case I'd simply try to determine the coordinates of the curve, let's call it I(lambda). Then I'd get the corresponding RGB-values, just above the wavelength-axis, that would give us the RGB-values at each wavelength, in an [n_lambda x 3] array. The total contributions to the R, G and B channels would then be the sum of the product of the respective intensities. You might have to scale those to be between 0 and 1 (or 0 and 255) for display-purposes.
I_of_lambda1 = % Your best estimate of the first curve
RGB = double(squeeze(IM(idx_xaxis+1,:,:)));
% make sure they have the same lengths.
Rtot = sum(I_of_lambda(:).*RGB(:,1));
Gtot = sum(I_of_lambda(:).*RGB(:,2));
Btot = sum(I_of_lambda(:).*RGB(:,3));
Then repeat procedure for second curve.
For more detailed discussion about spectral response and RGB-representations, take a look at Steve Eddins description: Making Color Spectrum Plots – Part 2
HTH
2 Comments
More Answers (0)
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!