# How I know the temperature scheme for COLORMAP_JET?

I want to print the equivalent temperature of a pixel of an image that is converted by COLORMAP_JET. e.g. an image is 100 x 100 in dimension, then the temperature array be like,

temp[] = {
{ 104, 1000, 600, .........},
{ 34, ,234, 678, ..........},
{ ..........................},
{ ..........................}
}


I want to store those temperatures in an array named temperature.

    applyColorMap(img, im_color, COLORMAP_JET);
count = 0;
for (int i = 0; i < img.rows; i++) {
for (int j = 0; j < img.cols; j++) {
temperature[count++] = ;/*get temperature here*/
}
}


How can I do that?

edit retag close merge delete

Sort by ยป oldest newest most voted

Instead of using temperature[count++] as the index, you could try temperature[j*img.rows + i].

In any case, a temperature is defined by a spectrum. By definition, one pixel does not produce a spectrum.

However, there is a peak photon wavelength in a spectrum, so technically you could use that as a way to get a temperature from only one pixel.

See Wien's displacement law https://en.wikipedia.org/wiki/Wien%27... for the formula Peak Wavelength = b/T, where b is Wien's constant, and T is temperature in Kelvins.

Also see Planck's law https://en.wikipedia.org/wiki/Planck%...

Good luck.

more

@sjhalaykatemperature[j*img.rows + i] will start from say 100, then what about previous indeices?

( 2019-09-15 02:04:03 -0500 )edit

No, it will start at j*img.rows + i, where j = 0 and i = 0 (it's the first loop iterations), and so the first index value is 0, not 100.

( 2019-09-15 12:54:48 -0500 )edit

Ok! I think I'm getting closer. So, how can I calculate peak photon wavelength in a spectrum for a pixel (RGB value)?

( 2019-09-18 12:47:06 -0500 )edit

@yasin -- The simplest solution would be to convert the image to HSV (see: COLOR_BGR2HSV).

The hue is the colour, which corresponds to a specific wavelength. Red has a wavelength of say 680 nanometres, green 540nm, and blue 470nm.

Search Google for 680 nanometres = ? metres, etc. That's how to convert the peak wavelength into metres: x. Once you convert from nanometres to metres, the temperature is simply T = b/x.

( 2019-09-18 19:16:40 -0500 )edit

( 2019-09-18 21:40:08 -0500 )edit

Thanks a lot. One more thing, shouldn't I suppose to get one temperature for each pixel? I mean according to your answer there will be three wavelengths (RGB) for each pixel.

( 2019-09-19 02:26:58 -0500 )edit

Yes, you are getting the temperature based on a single pixel.

You need to convert the image to HSV, so you only have to worry about one channel (wavelength): H.

( 2019-09-19 16:02:26 -0500 )edit

@yasin - are you using C++ or Python? Can you please supply a sample image?

( 2019-09-20 16:14:03 -0500 )edit

this is my current code with C++ in Visual studio, Thanks.

( 2019-09-21 01:54:59 -0500 )edit

Can you tell me why most temperatures dances between 4000 and 5500? Have a look at the rules:  w = 650 - (175 * h) / 240; l = w * 1e-9; temp[i][j] = (int)ceil(b / l);  You will find the project here.

( 2019-09-21 11:06:51 -0500 )edit

Official site

GitHub

Wiki

Documentation