Ask Your Question

How I know the temperature scheme for COLORMAP_JET?

asked 2019-09-14 06:54:36 -0500

yasin gravatar image

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-09-14 20:10:14 -0500

sjhalayka gravatar image

updated 2019-09-14 20:18:26 -0500

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 for the formula Peak Wavelength = b/T, where b is Wien's constant, and T is temperature in Kelvins.

Also see Planck's law

Good luck.

edit flag offensive delete link more


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

yasin gravatar imageyasin ( 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.

sjhalayka gravatar imagesjhalayka ( 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)?

yasin gravatar imageyasin ( 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.

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

Oh yes, and if you find my answer and comments to be helpful, then please upvote my answer and mark it as correct. Thank you!

sjhalayka gravatar imagesjhalayka ( 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.

yasin gravatar imageyasin ( 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.

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

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

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

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

yasin gravatar imageyasin ( 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.

yasin gravatar imageyasin ( 2019-09-21 11:06:51 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-09-14 06:54:36 -0500

Seen: 40 times

Last updated: Sep 14