I need to convert rgb image into thermal image for temperature detection of human being without using any thermal camera or any sensors is there any way in matlab or other way to obtained thermal image.

204 views (last 30 days)
I need to convert rgb image into thermal image for temperature detection of human being without using any thermal camera or any sensors is there any way in matlab or other way to obtained thermal image.

Answers (2)

Image Analyst
Image Analyst on 15 Jan 2017
Here's a demo I did for someone else. It turns the RGB image into a grayscale image but that's as far as you can get unless you know what gray level corresponds to what temperature. Your camera should be able to give that to you.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
% Get the name of the image the user wants to use.
baseFileName = 'thermal_image.png'; % Assign the one on the button that they clicked on.
% Get the full filename, with path prepended.
folder = pwd
fullFileName = fullfile(folder, baseFileName);
% Read in a demo image.
originalRGBImage = imread(fullFileName);
% Display the image.
subplot(2, 3, 1);
imshow(originalRGBImage, []);
axis on;
caption = sprintf('Original Pseudocolor Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
grayImage = min(originalRGBImage, [], 3); % Useful for finding image and color map regions of image.
% Crop off the surrounding clutter to get the colorbar.
colorBarImage = imcrop(originalRGBImage, [533, 45, 13, 249]);
b = colorBarImage(:,:,3);
% Crop off the surrounding clutter to get the RGB image.
rgbImage = imcrop(originalRGBImage, [20, 40, 441, 259]);
% Get the dimensions of the image.
% numberOfColorBands should be = 3.
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Display the image.
subplot(2, 3, 2);
imshow(rgbImage, []);
axis on;
caption = sprintf('Cropped Pseudocolor Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo();
% Display the colorbar image.
subplot(2, 3, 3);
imshow(colorBarImage, []);
axis on;
caption = sprintf('Cropped Colorbar Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Get the color map.
storedColorMap = colorBarImage(:,1,:);
% Need to call squeeze to get it from a 3D matrix to a 2-D matrix.
% Also need to divide by 255 since colormap values must be between 0 and 1.
storedColorMap = double(squeeze(storedColorMap)) / 255
% Convert from an RGB image to a grayscale, indexed, thermal image.
indexedImage = rgb2ind(rgbImage, storedColorMap);
% Display the thermal image.
subplot(2, 3, 4);
imshow(indexedImage, []);
axis on;
caption = sprintf('Indexed Image (Gray Scale Thermal Image)');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
% Get the histogram of the indexed image
subplot(2, 3, 5:6);
histogram(indexedImage, 'Normalization', 'probability');
axis on;
grid on;
caption = sprintf('Histogram of Thermal Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Gray Scale', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Frequency', 'FontSize', fontSize, 'Interpreter', 'None');
Walter Roberson
Walter Roberson on 14 May 2022
It is never necessary to convert the rgb to grayscale, and can be a logic error if you do that, as two different rgb can convert to the same grayscale.
What is necessary is to have a complete table matching all possible rgb values that can appear, into temperatures, as I described in my Answer. If r, g, b are each 8 bits, the required lookup table only requires 2^24 entries, at most 1 gigabytes of lookup information.
It is not promised that the rgb colours make any sense in terms of temperature.

Sign in to comment.

Walter Roberson
Walter Roberson on 15 Jan 2017
You need to know how temperature was converted to RGB. Unfortunately that is not a linear process: for example, it is not as easy as "red increases as color increases". Thermal images also do not represent color the same way that flame color changes with temperature (flames get bluer and less visible as temperatures increase.) You either need to get a temperature map from the manufacturer or else you need to calibrate the image.
Once you have a table of which color goes with which temperature, then you can probably use rgb2ind to convert the rgb to intensity number that you could then use to index the temperature table (in case it is not linear)
I have looked into this topic a couple of times but I have not found any standard for representing temperature with color.
Walter Roberson
Walter Roberson on 16 Jan 2017
If you had an image that was strictly pseudo-colored, and you knew the maximum number of colors (e.g., if you knew it had been produced from 8 bits worth of temperature), and the maximum number of colors is at most 65535, then you could call rgb2ind() with the number of colors in order to convert to an un-ordered index map that label each of the different colors with a unique number.
Unfortunately knowing which pixels are the same color as a given pixel does not give you any information about what temperature those pixels correspond to. There cannot be a single standard color to temperature conversion because different thermal cameras measure across different bands and are scaled for different intensities.
Sometimes the scaling is relative rather than absolute, the same way that just looking at a grayscale picture of a scene does not tell you whether the value 137 corresponds to "pretty dark" or "pretty bright but not as bright as maximum". Potentially a single thermal camera might be used to record snow fox burrows in the snow (in which case 255 might be the opening and 137 might be a small way under the snow from the opening); and then taken and used to record human veins (in which case fractions of a degree near 38C might be important); and then taken and used to record a building fire (in which case the hottest part might be well over 1500 C). Without knowing the settings the picture was taken at, you might not be able to decide temperatures even if you were able to convert the color to consecutive grayscale properly.
Therefore you either need a calibration image at those same settings, or you need a colorbar in the image, or you need information from the manufacturer (or who-ever did the post-processing) about how to match color to temperature.
Temperatures of RGB images of flames do not increase linearly as grayscale brightness increases. See http://maggiemaggio.com/color/2011/08/fire-ii-color-and-temperature/ for some images. The hotter the flame, the more blue-shifted it is, and perceived brightness for humans is least sensitive to RGB.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!