false-/pseudo color coding for temperature

3.5k views Asked by At

I have some temperature values in a given range, lets say between 0-100 Celsius. Now I want to map these values to colors, so blue=RGB(0,0,255) means 0°C, red=RGB(255,0,0) means 100°C and the colors in between mean some temperatures in between.

Matlab actually has a function called colormap. My stuff is implemented in OpenCV & C++. Is there anyone, who already has some experience in color coding or knows any good mathematical way to do that?

3

There are 3 answers

2
Will Vousden On BEST ANSWER

The HSV colourspace might be helpful here.

Hue is periodic, however,, which is to say if you go from red all the way to the other end of the spectrum, you'll be back at red, which isn't that useful in your case. What you'll probably want to do is choose a subset of the hue spectrum that goes from red, through yellow and green, to blue (omitting pink/purple). There's an image in the RGB-HSV section that should show you what I mean.


Update: In fact, this previous answer tells you how to implement exactly the MATLAB Jet palette that you describe.

It seems that Jet is actually a variation on the HSV colourspace anyway!

0
dgw On

For temperatur (t) from 0 to 100 you could calculate each color:

Pseudocode:
  Col(t)=(  0+INT(2.55*t), // Red
            0,             // Green
          255-INT(2.55*t)) // Blue
Col(0)  =(0,0,255)
Col(100)=(255,0,0)

The factor 2.55 comes from the given Max/Min Values of 0° and 100° Celsius. You just have to choose your intervals now.

Hope that helps.

0
siliconwafer On

It sounds like you want a JET colormap, which begins at dark blue and ends at dark red.

Assuming you have a set of temperatures from 0 to 100, incrementing by one:

temps = 0:1:100;

Use the JET function to create the set of colors over N points, where N is the length of your temperature vector:

colors = jet(length(temps));

Now, to access the color for the first temperature (this will give blue):

colors(1,:)

Or the colors for the last temperature (this would be red):

colors(end,:)