HELP Simple Spectral Conversion to RGB

Hello,

I’m new to these forums and colorimetry in general, but I’ve done a bit of research over the past few days and understand the general concept of color spaces, device-dependent color gamuts, CIE XYZ, CIE RGB, sRGB, etc. However, I’m still stuck on a seemingly simple problem…

I have a material that I am imaging in a microscope with a standard digital microscope camera. I’m trying to theoretically reproduce the color I’m seeing in the pictures using its theoretical reflection spectrum.

All I want to do is convert a reflection spectrum to (R,G,B) values so that I can tell MATLAB to display this color on screen. So far I’ve tried integrating over the CIE RGB color matching functions, but of course I get negative numbers. If I instead integrate over CIE XYZ color matching functions and convert to sRGB I still get negative number (out of gamut I guess). How do I fix this problem?

I’m guessing I either have to…

  1. Find some sort of algorithm that converts out of gamut sRGB into sRGB; or…
  2. Instead integrate over my microscope camera’s sensitivity spectra for R,G,B

Can anyone help??

So nobody knows? That’s surprising.

Browse around at www.brucelindbloom.com. Math formulae for Spectrum-XYX-RGB, and excel sheets as well.

Yes that’s all great, but most of my colours of out of gamut in RGB… I’m looking for equations to convert these colours to in-gamut colours OR programs that do this conversion for me.

Any help?

I don’t seem to understand why most websites ignore this issue… it seems pretty important. How am I supposed to plot an RGB of (-1.2, 1.3, -0.5)?? The computer’s not likin’ it…

Maybe you could explain exactly how your are calculating/arriving at those RGB values? From my background (admittedly non-scientific), they don’t seem logical. If you have spectral reflectance data, you can send it to me offlist if you like.

Thanks for your help. I emailed you but just for anyone else here, I have one example reflection spectrum that yields XYZ tristimulus values of (0.1, 0.1, 0.4) and converting to RGB you get (-0.23, 0.36, 0.77) as verified by the calculator on www.brucelindbloom.com

What do I do?

The issue here appears to be one of scaling. There is an explanation on Bruces website, but essentially the RGB values youre deriving are scaled for 0 1.0, instead of 0 255 (256 levels of gray for an 8-bit image). Clicking the scale RGB button correctly scales this to 0-255 and the values are now 59.6, 92, 195.1. Negative values are indicative of out-of-gamut colors and are clipped to zero by most applications (indeed Photoshop will yield values of 0, 90, 195 (with rounding accounting for the difference) when entering the CIELab values derived from your XYZ). So it appears your calculations are correct, just need scalling and clip the negative integers to zero for the closest reproducible color.

Mike

Okay great thanks for the help. I knew about the scaling difference but I was using the convention that all XYZ and RGB values are between 0 and 1. But I did not think you could just “clip” the negative values to zero. I thought of that but just wanted someone else to confirm. I don’t really need “exact” colours anyway.

But I just tried clipping my negative values and the RGB plots look a lot closer to what I expect so I’ll go with that.

Thanks again!

I know it is not easy problem, I find some articles (f.e. “An RGB to Spectrum Conversion for Reflectances”)

But is here a anther way if i have light spectrum?

so

measured RGB + light spectrum => spectrum (of measured color)


additionaly:

RGB picture + known light spectrum => spectrums of every pixel

and

spectrum of every pixel + another light spectrum => picture in different light conditions?

I think I follow you, and if I understand you correctly, there is a good way to illustrate this using ColorThink Pro. CTP has a Worksheet feature that allows you to lay out a real or simulated workflow anyway you want.

There’s a preset workflow in the Guide section called Evaluate Device Tone Stability. Here you would give the software a color list (like an RGB measurement file) that contains spectral information. Then the Guide will automatically lay out for you a work flow comparing that measurement information under D50 lighting and under D65 lighting so you can see the difference between the two illuminants. ColorThink has something like 20 different illuminants built in that you can use, and I think you can add your own too. This is a little known feature of ColorThink, so thanks for bringing it up.