I am looking for an algorithm that will map a range of floats to RGB.

Started by
9 comments, last by CelticDaddio 14 years, 9 months ago
I am looking for an algorithm that will map a range of floats to RGB. My google skills are apparently lacking as I can find exactly what I need. Here is what I want to do: I have a range of floats: fmin <= f <= fmax I want to map f to RGB such that fmin = RGB(0,0,0) fmax = RGB(255,255,255) Any suggestions? Pointers to reading info? etc? CD
Advertisement
Your problem is underconstrained. You just want to go from black to white, with just grays in between? Fine. R = G = B = (f-fmin)/(fmax-fmin) * 255. If you want colors, you'll need to describe what you want in there.
Sorry,

I am trying to map the range of floats to a color image. Let's say the input data is a temperature map. I want all pixels at the same temp to be a particular color which isn't gray. As an example see this image:

http://www.maxmax.com/images/Cameras/TIR2/CatColdToHotBlue.jpg

CD

Quote:Original post by Sneftel
Your problem is underconstrained. You just want to go from black to white, with just grays in between? Fine. R = G = B = (f-fmin)/(fmax-fmin) * 255. If you want colors, you'll need to describe what you want in there.


Start with a color for fmin and a color for fmax. Linearly interpolate all values in between. If that isn't what you want, choose a float value that isn't to your liking. Decide what color it should be. Linearly interpolate between that float point and the color points on either side. Repeat until you're happy with the gradient.

It's possible to do this with third party tools like Gimp's gradient editor.
I would recommend looking into HSL/HSV, as I think it would make interpolating between colors (like SiCrane suggested) easier. You can then use a conversion routine to get them in the RGB format (First result on Google.)
So given my point to convert f in [fmin,fmax] I would interpolate R, G and B independent of each other...

Rmin <= R <= Rmax
Gmin <= G <= Gmax
Bmin <= B <= Bmax

R(f) = Rmin + (f - fmin)(Rmax-Rmin)/(fmax-fmin)
G(f) = Gmin + (f - fmin)(Gmax-Gmin)/(fmax-fmin)
B(f) = Bmin + (f - fmin)(Bmax-Bmin)/(fmax-fmin)

Wouldn't that just generate a gray scale?

CD


Quote:Original post by SiCrane
Start with a color for fmin and a color for fmax. Linearly interpolate all values in between. If that isn't what you want, choose a float value that isn't to your liking. Decide what color it should be. Linearly interpolate between that float point and the color points on either side. Repeat until you're happy with the gradient.

It's possible to do this with third party tools like Gimp's gradient editor.


That would indeed be a grey scale since you managed to skip steps 3 to 8 in the algorithm I gave you. You only stop at step 2 if you've decided that's what you want. You obviously don't, so go on and do steps 3 to 8.
I guess I don't understand what you are saying and what steps 3-8 are.

Quote:Original post by SiCrane
That would indeed be a grey scale since you managed to skip steps 3 to 8 in the algorithm I gave you. You only stop at step 2 if you've decided that's what you want. You obviously don't, so go on and do steps 3 to 8.


If you map the color to greyscale you could then use that 0-255 value to index into a palette.
Pre define a 256 color palette ranging from blues up to bright reds for temperatures.
I do this a slightly different way. I have a texture that I use as the colour ramp and normalize the range of values from 0.0-1.0. Then use this value to look up into the texture. You can then use a variety of texture colour ramps quickly and easily.

If you dont want to use textures this site might be useful:

http://local.wasp.uwa.edu.au/~pbourke/texture_colour/colourramp/

It provides a nice description along with some look up tables for various gradients.

HTH

This topic is closed to new replies.

Advertisement