Put It Into Reverse: Image Color to Value


Here is the problem I am busy singing (well not actually singing because for me that would be a very bad thing) the praises if IP with one of my clients and the request comes up. They do CFD simulations and often times the internal client says well what is the difference between the two cases. At this time they have images (bmp files) of the analysis which takes 24 hours to run and the exported data is many GB.

So the request was can you just subtract one image from the other? And yes you can with some caveats about using a float wave to preserve the negative numbers. In a proof of concept I converted the color bmp to grayscale and did the subtraction. What I really should do is convert the color of the pixel to an accurate value. For arguments sake let's assume that the color mapping is a rainbow and I know the values of minimum and maximum, say rainbow going from 0 to 50. What would be the methodology to read the pixel color and translate it back to a value within the range?

If the LUT is linear grayscale (or black-red, black-green) this is pretty simple, but a rainbow colour table is a challenge. My guess would be to make the 3 column colour wave and then interpolate (in this case downsample) to your min and max. Then use those values as xyz coords and find the point nearest to the colour you want to get the value?

You can make colour tables with
#include <ColorWaveEditor>

It's worth reading this excellent blog post by Jim Prouty which has a method for extracting values from a colour key.
If it is at all possible to output the CFD simulation as a grey scale image I would strongly suggest you do that and don't create the color scale image until you are finished with all your analysis steps.

But if that is not possible and you have a color-scale image and want to convert it to actual values, I would not convert it to grey scale, since two colors (and therefore two values) might be the same shade of grey. I would probably do the conversion using only one channel red, green or blue. Or you could do all three channels separately and compare the result. If the conversion factor is linear you could do:


If the conversion is not linear you will need to create a conversion factor wave and do:

If you have a Rainbow color table associated with your image, then the underlying image should be a 2D matrix wave with some sort of "intensity" values. Those are the numbers you're looking for, are they not?

John Weeks
WaveMetrics, Inc.