How to Detect the hottest spot in a thermal video

Hello, I have a thermal video from a professional camera and how have to find the hottest point regarding temperature in this video. Would you please like to tell me how can I do this? I imported thermal image from this video and applied threshold it gives the values but after that it doesn't locate the hottest spot. Thanking you in anticipation.

3 Comments

Please upload an example image and the code you have so far
Is the video greyscale data or is it color? If it is color then you need to know the temperature to color transformation that was applied.
@David Barry Image for your information. Thanks

Sign in to comment.

 Accepted Answer

Assuming the video is grayscale (hopefully) you can get each frame, then do
maxValue = max(thisFrame(:));
[rows, columns] = find(thisFrame == maxValue);
That will give you the row(s) and column(s) where the brightest value (max temperature) occurs. If it's a pseudocolored video, then you'd need the color map and scan your frame and for each pixel determine which index in the colormap does that color appear.

11 Comments

If you have the colormap then rgb2ind() can return the index information. But knowing the colors is not enough: you need to know how the colors rank in temperature. The "last" color in whatever color map you are given does not necessarily correspond to the hottest color.
You might potentially get lucky and have it turn out that the value of one of the channels (e.g., the red channel) is ordered by increasing temperature. But you cannot assume that at all.
If what you are given is images of the color of the flame (in normal atmosphere) taken with a normal camera (not a specially constructed scientific device), then going from RGB to wavelength and then to temperature turns out to have a number of difficulties.
Thank you for explanation. As thermal video/image usually consist of red, blue, green or yellow. So definitely red is the for the maximum temperature. So should I convert it into gray scale first and then try to find the high intensity spot? Thanks again regards
"So should I convert it into gray scale first and then try to find the high intensity spot?"
No! You need a formal description of how the color corresponds to temperature! It might not have much to do with gray scale intensities.
Try this:
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
clearvars;
close all;
format long g;
format compact;
fontSize = 20;
%===============================================================================
% Get the name of the demo image the user wants to use.
% Let's let the user select from a list of all the demo images that ship with the Image Processing Toolbox.
folder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
% Demo images have extensions of TIF, PNG, and JPG. Get a list of all of them.
imageFiles = [dir(fullfile(folder,'*.TIF')); dir(fullfile(folder,'*.PNG')); dir(fullfile(folder,'*.jpg'))];
for k = 1 : length(imageFiles)
% fprintf('%d: %s\n', k, files(k).name);
[~, baseFileName, extension] = fileparts(imageFiles(k).name);
ca{k} = [baseFileName, extension];
end
% Sort the base file names alphabetically.
[ca, sortOrder] = sort(ca);
imageFiles = imageFiles(sortOrder);
button = menu('Use which gray scale demo image?', ca); % Display all image file names in a popup menu.
% Get the base filename.
baseFileName = imageFiles(button).name; % Assign the one on the button that they clicked on.
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
%===============================================================================
% Read in a standard MATLAB gray scale demo image.
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', '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')
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(grayLevels, pixelCount); % Plot it as a bar chart.
grid on;
title('Histogram of original image', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Gray Level', 'FontSize', fontSize);
ylabel('Pixel Count', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Apply a colorbar
rgbImage = ind2rgb(grayImage, jet(256));
% Display the image.
subplot(2, 2, 3);
imshow(rgbImage, []);
colorbar
title('Psuedocolored Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Try to recover the indexed image from the RGB image and the colormap
indexedImage = rgb2ind(rgbImage, jet(256));
% Find the bright value
maxValue = max(indexedImage(:))
% Display the image.
subplot(2, 2, 4);
imshow(indexedImage, []);
title('Recovered Thermal Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Find the max locations
[rows, columns] = find(indexedImage == maxValue);
% Plot them.
markerSize = 20;
hold on;
for k = 1 : length(rows)
plot(columns(k), rows(k), 'r+', 'MarkerSize', markerSize);
plot(columns(k), rows(k), 'ro', 'MarkerSize', markerSize);
end
Thank You for this example. I had to find the required temperature values from my ROI in a thermal video. I extracted some frames and extracted the region of interested that is still in the form of pixels. Now I want to map temperature values to that ROI from my excel file that is basically extracted from the same frame. After that I have to test whether the values are exactly from the region of interest or not? Any idea about that or any example. Waiting for you kind response. Thanks
Not exactly sure what " Now I want to map temperature values to that ROI from my excel file that is basically extracted from the same frame" means but if your ROI is a binary image mask, you can do
thermalImage(mask) = someValue;
To see if some value is in your ROI, you can do this:
pixelsInROI = thermalImage(mask);
if max(pixelsInROI == someValue) == 1
% someValue is the value of at least one of the pixels.
else
% someValue is NOT the value of at least one of the pixels.
end
Dear Image Analyst,
Thank you for your example it is very complete! I have color map which relates temperature in ºC with color and will like to print right next to "Red Target Icon" the temperature of the "Target".
How do you suggest i should do this? - Should I first extract the ROI related to the color map?
Thank you in advance, MRa.
You can get the 'Position' property of the colorbar, then use text() to place a text string anywhere you want on the figure.
Can the code here be run with another tiff file or can I run it with an image with another tiff extension?
Sure. You just need to change the filename, and the location in your image where we need to crop the image and the colorbar.

Sign in to comment.

More Answers (2)

Behnaz Molaei
Behnaz Molaei on 22 Apr 2018
Edited: Behnaz Molaei on 22 Apr 2018
Dear Image Analyst
I have a thermal image that I have imported in MATLAB in CSV format and I need to choose places that I used (imrect) function and now I need to get the average temperature inside that ROI(Rectangular). Now when I run it, it gives me the same amount for all of the rectangular and it is not the average temperature. Would you please help me?

2 Comments

mean_inside_mask = sum(YourImageData(:) .* roimask(:)) ./ sum(roimask(:));

If the mask is binary, you can do:

meanTemperature = mean(temperatureImage(mask));

Sign in to comment.

Please how do I extract the hottest frame/image from a thermal video? I've been searching for the MATLAB code but haven't found any. I have a lot of thermal videos to process and manually searching the videos frame by frame usually makes my research work tedious. Please can anyone help me with the MATLAB code that can enable me to extract the exact hottest frame from a thermal video? Thank you in advance.

1 Comment

How do you define the "hottest" frame? Is that the frame for which the sum of the heat is highest? Is the relationship between pixel value and heat linear?
Thermal images are often available as colorized rather than as raw data. If your images are already colorized then you have to start by transforming back from pixel color into heat value, and that is typically not a linear transformation.
Unfortunately, manufacturers' documentation on how color corresponds to temperature can be difficult to find, with some manufacturers refusing to say. In those circumstances it is necessary to start by calibrating the camera.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!