RGB to Wavelength, is it possible?

Is it possible to generate a histogram based on wavelength (visible light), rather than RGB values? Even if it is a slight approximation, it would be very useful.

Risposte (1)

Walter Roberson
Walter Roberson il 7 Set 2015

1 voto

4 Commenti

Is this true universally or just with matlab? I'd be willing to try other programs such as imageJ
Universally. Many RGB colors are mixes of multiple frequencies.
If you look in the above link at the second newsreader thread you will see that William linked to http://www.mathworks.com/matlabcentral/fileexchange/7021-spectral-and-xyz-color-functions from the File Exchange. Those functions are for converting spectra to RGB.
Since you are fine with an approximation, then there is an approach that might be "good enough" for you:
  1. create a color transform that converts the RGB to XYZ
  2. run the input RGB and run it through the transform
  3. permute() the order of that result -- reversing the transformation at the end of http://www.mathworks.com/matlabcentral/fileexchange/7021-spectral-and-xyz-color-functions/content/spectrumRGB.m
  4. pick a formulary and retrieve its matching function by using http://www.mathworks.com/matlabcentral/fileexchange/7021-spectral-and-xyz-color-functions/content/colorMatchFcn.m
  5. for each location, find the shortest distance between the XYZ values and the values in columns 2:4 of the match data, determining the index of the match
  6. retrieve the corresponding spectral index from the first column of the match data
  7. permute and reshape as necessary to create an indexed image
You could probably improve on the matching by using TriScatteredInterp or the equivalent, as that would be able to give you fractional frequencies instead of whole number frequencies.
The accuracy is going to depend a lot on the illuminating frequency and upon whether you choose the right model (formulary).
I do not know enough about color science to know how to take the illuminant into account even if it was known.
But you did say "even if it was a slight approximation"...
Like I said in the link Walter referred you to, Some arbitrary RGB does not necessarily map to one single pure wavelength. A single RGB triplet of values might be arrived at from a whole broad spectrum of wavelengths, not just one wavelength. This is general color science, not something specific to MATLAB.
Not only that but there can be "metamers" - spectra that are completely different but that give the same RGB values. Google metamerism to learn more.
You might be interested in this link or this one or this one.
what is the correct way to perform steps 3-7?

Accedi per commentare.

Richiesto:

il 7 Set 2015

Commentato:

il 7 Set 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by