Thermal camera image processing
Mostrar comentarios más antiguos
I'm working on thermal camera image processing and I would like to create an equation to show what every pixel means in temperature. How can I create such equation and how can I put it in the code so it can give me temperatures for certain colors?
5 comentarios
Shiwani Dhamodaran
el 29 de Dic. de 2019
where u able to find a code for this or some linear equation for calculating the temperature of each pixel
if anybody else also has a suggestion please notify
Image Analyst
el 29 de Dic. de 2019
You need to scroll down. If you do, you'll find this answer.
Shiwani Dhamodaran
el 30 de Dic. de 2019
tanq i found what i want but if i want to use it in fpga i need to use hdl coder for that i have to create two file one in which i have to make a function call and the other one in which i have to use test cases.
in this code where can i make a function call
can u pls help me
Kiran Kintali
el 30 de Dic. de 2019
Please see mlhdlc_heq.m and mlhdlc_heq_tb.m demo files on how to do this. Thanks.
Shiwani Dhamodaran
el 2 de En. de 2020
thanks i will try and tell u if i have any problem
Respuesta aceptada
Más respuestas (6)
Image Analyst
el 24 de Feb. de 2018
0 votos
See attached demo.
10 comentarios
Nasser Jarrar
el 24 de Feb. de 2018
Editada: Image Analyst
el 25 de Feb. de 2018
Image Analyst
el 24 de Feb. de 2018
You forgot to attach '11.png'. And it had better have a colorbar in there or there is no way to tell what color corresponds to what temperature, unless you have some kind of array from some other source that tells you that.
Nasser Jarrar
el 24 de Feb. de 2018
Image Analyst
el 25 de Feb. de 2018
You just simply need to modify the low and high temperature, and adjust the row and column where the image and colorbar are taken from.
See my second answer. I did it for you.
RICHA SINGH
el 16 de Jun. de 2021
I am facing some error in running this code
RICHA SINGH
el 16 de Jun. de 2021
@Naseer have you got the solution of your problem?
Image Analyst
el 17 de Jun. de 2021
@RICHA SINGH, yes he did get the solution to his problem. He kindly accepted my answer. It's the one with the green line and check mark above it and says "Accepted Answer".
RICHA SINGH
el 17 de Jun. de 2021
Image Analyst
el 17 de Jun. de 2021
@RICHA SINGH, look at your color bar! You did not modify the code to crop YOUR color bar out. You simply used the code I gave, which was for a different image, so your color bar is not the full, actual color bar used in your image. Make that adjustment and it should work.
RICHA SINGH
el 17 de Jun. de 2021
ok sir thank you
mr.hien tran
el 5 de Oct. de 2018
0 votos
excuse me sir. can you help me ? I'm working on thermal image processing How can i find the highest temperature in infrared image?? please!!!
monika SINGH
el 16 de Mayo de 2019
Editada: Image Analyst
el 8 de Abr. de 2022
Image Analyst, with your code below:
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 = '11.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');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
grayImage = min(originalRGBImage, [], 3); % Useful for finding image and color map regions of image.
% Get the dimensions of the image. numberOfColorChannels should be = 3.
[rows, columns, numberOfColorChannels] = size(originalRGBImage);
% Crop off the surrounding clutter to get the colorbar.
colorBarImage = imcrop(originalRGBImage, [1, 20, 17, rows]);
b = colorBarImage(:,:,3);
% Crop off the surrounding clutter to get the RGB image.
rgbImage = imcrop(originalRGBImage, [81, 1, columns-20, rows]);
% 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');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
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');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% 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
% Need to flip up/down because the low rows are the high temperatures, not the low temperatures.
storedColorMap = flipud(storedColorMap);
% 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 Image)');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Define the temperature at the top end of the scale
% This will probably be the high temperature.
highTemp = 28.9;
% Define the temperature at the dark end of the scale
% This will probably be the low temperature.
lowTemp = 0.9;
% Scale the image so that it's actual temperatures
thermalImage = lowTemp + (highTemp - lowTemp) * mat2gray(indexedImage);
subplot(2, 3, 5);
imshow(thermalImage, []);
axis on;
colorbar;
title('Floating Point Thermal (Temperature) Image', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Let user mouse around and see temperatures.
hp.Units = 'normalized';
hp.Position = [0.45, 0.03, 0.25, 0.05];
% Get the histogram of the indexed image
subplot(2, 3, 6);
histogram(thermalImage, 'Normalization', 'probability');
axis on;
grid on;
caption = sprintf('Histogram of Thermal Temperature Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Temperature', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Frequency', 'FontSize', fontSize, 'Interpreter', 'None');
IN THE ABOVE CODE, ARE YOU SURE IT GIVES ACCURATE TEMPERATURE W.R.T TEMPERATURE??
AND WHAT IS SIGNIFICANCE OF COLORBAR
4 comentarios
Apra Gupta
el 30 de Jun. de 2021
@Image Analyst, Hello Sir, My Thermal Image is in the format .IS2. How can I read it in MATLAB.
Image Analyst
el 30 de Jun. de 2021
@Apra Gupta, I have no idea how to read .IS2 format images. Ask your camera manufacturer for code to read it in, preferably in MATLAB. Otherwise translate it into MATLAB.
Apra Gupta
el 30 de Jun. de 2021
Ok Sir, Right now I m converting my images to JPEG and then working on it, bt in its JPEG format the information related to temperature gets lost.
Image Analyst
el 8 de Abr. de 2022
Editada: Image Analyst
el 8 de Abr. de 2022
@monika SINGH, with my code above that you posted, it's as accurate as your color bar is. I'm sure it's not as accurate as if you could just get the temperature image directly from your camera but as far as how many degrees off it is, I can't say. It depends on the range of temperatures in the colorbar and how bad the JPG artifacts in the image are, and how accurately you specify the color bar coordinates.
The colorbar tells you how to convert an RGB value into a temperature.
Andrew Oliver
el 8 de Abr. de 2022
0 votos
@Image Analyst I would like to use and reference your code in an undergrad project that I am currently doing which deals with a basic thermal imaging analysis system using MATLAB, would you be able to share with me the appropriate way to cite this? Many thanks
1 comentario
Image Analyst
el 8 de Abr. de 2022
@Andrew Oliver, an example of how Mathworks suggests code be cited can be found on this page:
Jacob Kalmanovich
el 14 de Jun. de 2022
Hello, my apologies to ask another question. I am fairly new to matlab and am have a similar problem.
I used a similar code for my image which I attached. I understand that my issue is because I did not properly crop the colorbar, however I am not completely aware on how to do that. Would you please offer me your assistance in this matter? Thank 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 = '11.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');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
grayImage = min(originalRGBImage, [], 3); % Useful for finding image and color map regions of image.
% Get the dimensions of the image. numberOfColorChannels should be = 3.
[rows, columns, numberOfColorChannels] = size(originalRGBImage);
% Crop off the surrounding clutter to get the colorbar.
colorBarImage = imcrop(originalRGBImage, [1, 20, 17, rows]);
b = colorBarImage(:,:,3);
% Crop off the surrounding clutter to get the RGB image.
rgbImage = imcrop(originalRGBImage, [81, 1, columns-20, rows]);
% 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');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
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');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% 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
% Need to flip up/down because the low rows are the high temperatures, not the low temperatures.
storedColorMap = flipud(storedColorMap);
% 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 Image)');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Define the temperature at the top end of the scale
% This will probably be the high temperature.
highTemp = 28.9;
% Define the temperature at the dark end of the scale
% This will probably be the low temperature.
lowTemp = 0.9;
% Scale the image so that it's actual temperatures
thermalImage = lowTemp + (highTemp - lowTemp) * mat2gray(indexedImage);
subplot(2, 3, 5);
imshow(thermalImage, []);
axis on;
colorbar;
title('Floating Point Thermal (Temperature) Image', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Let user mouse around and see temperatures.
hp.Units = 'normalized';
hp.Position = [0.45, 0.03, 0.25, 0.05];
% Get the histogram of the indexed image
subplot(2, 3, 6);
histogram(thermalImage, 'Normalization', 'probability');
axis on;
grid on;
caption = sprintf('Histogram of Thermal Temperature Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Temperature', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Frequency', 'FontSize', fontSize, 'Interpreter', 'None');
5 comentarios
Subasri Raaja Anjana
el 11 de Oct. de 2022
Editada: DGM
el 4 de Mzo. de 2023
% Take a thermal RGB image from the FLIR One camera and uses the embedded color bar to determine temperatures from the colors and make a temperature image.
% Input is a thermal RGB image from a thermal camera, such as the FLIR One camera,
% that has a pseudocolored image and a colorbar all in the same image.
% User is asked to draw a rectangle around the thermal image part of the image,
% and the colorbar part of the image. User is asked for the min and max temperatures
% at the end of the colorbar. It then the embedded color bar to create a mapping of
% RGB color into temperatures in degrees F or F. It then determines temperatures from
% the colors for every pixel in the image and make a temperature image.
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';
% Get the full filename, with path prepended.
folder = pwd; % Change to whatever folder the image lives in.
fullFileName = fullfile(folder, baseFileName); % Append base filename to folder to get the full file name.
if ~isfile(fullFileName)
warningMessage = sprintf('Default image %s not found.\nPlease select one.', fullFileName);
uiwait(warndlg(warningMessage));
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(folder, '*.*');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName);
% errorMessage = sprintf('Error: file not found:\n%s', fullFileName)
% uiwait(errordlg(errorMessage));
return;
end
fprintf('Transforming image "%s" to a thermal image.\n', fullFileName);
%===============================================================================
% Read in a demo image.
hFig = figure;
originalRGBImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(originalRGBImage)
% Display the image.
imshow(originalRGBImage, []);
hFig.WindowState = 'maximized'; % Maximize the window so it's easier to draw.
axis on;
caption = sprintf('Original Pseudocolor Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
grayImage = min(originalRGBImage, [], 3); % Useful for finding image and color map regions of image.
%=========================================================================================================
% Need to crop out the image and the color bar separately.
% First crop out the image.
roiPosition = GetRectangularROI('Drag a box out over the portion of the image you want to analyze.');
% roiPosition is [xLeft, yTop, width, height]
imageRow1 = round(roiPosition(2));
imageRow2 = round(imageRow1 + roiPosition(4));
imageCol1 = round(roiPosition(1));
imageCol2 = round(imageCol1 + roiPosition(3));
% Nominal values for the demo image:
% imageRow2 = 298;
% imageCol2 = 460;
% Validate these numbers because sometime the "2" coordinate is one past the edge of the image.
if imageRow2 > rows || imageCol2 > columns
% warningMessage = sprintf('Error: you are trying to extract the thermal scene image\nfrom an area outside the actual image.\nThe size of the full image is %d rows by %d columns.\nYou are trying to extract from row %d to %d, and from column %d to %d, which is outside the image.\nI will fix it for you.',...
% rows, columns, imageRow1, imageRow2, imageCol1, imageCol2);
% uiwait(warndlg(warningMessage));
% Clip the coordinates so they fit.
imageRow1 = min(imageRow1, rows);
imageRow2 = min(imageRow2, rows);
imageCol1 = min(imageCol1, columns);
imageCol2 = min(imageCol2, columns);
end
% Put up a rectangle over the original image showing where we cropped out of.
rectanglePosition = [imageCol1, imageRow1, imageCol2 - imageCol1, imageRow2 - imageRow1];
hold on;
rectangle('Position', rectanglePosition, 'EdgeColor', 'r', 'LineWidth', 2);
% Crop off the surrounding clutter to get the RGB image.
rgbImage = originalRGBImage(imageRow1 : imageRow2, imageCol1 : imageCol2, :);
% imcrop(originalRGBImage, [20, 40, 441, 259]);
% Next, crop out the colorbar. Define the location for this particular image.
roiPosition = GetRectangularROI('Drag a box out over the color bar only.');
% roiPosition is [xLeft, yTop, width, height]
colorBarRow1 = round(roiPosition(2));
colorBarRow2 = round(colorBarRow1 + roiPosition(4));
colorBarCol1 = round(roiPosition(1));
colorBarCol2 = round(colorBarCol1 + roiPosition(3));
% Nominal values for the demo image:
% colorBarRow1 = 45;
% colorBarRow2 = 293;
% colorBarCol1 = 533;
% colorBarCol2 = 545;
% Validate these numbers because sometime the "2" coordinate is one past the edge of the image.
if imageRow2 > rows || imageCol2 > columns
% warningMessage = sprintf('Error: you are trying to extract the thermal scene image\nfrom an area outside the actual image.\nThe size of the full image is %d rows by %d columns.\nYou are trying to extract from row %d to %d, and from column %d to %d, which is outside the image.\nI will fix it for you.',...
% rows, columns, imageRow1, imageRow2, imageCol1, imageCol2);
% uiwait(warndlg(warningMessage));
% Clip the coordinates so they fit.
colorBarRow1 = min(colorBarRow1, rows);
colorBarRow2 = min(colorBarRow2, rows);
colorBarCol1 = min(colorBarCol1, columns);
colorBarCol2 = min(colorBarCol2, columns);
end
% Crop out the color bar image by itself.
% Crop off the surrounding clutter to get the colorbar.
colorBarImage = originalRGBImage(colorBarRow1 : colorBarRow2, colorBarCol1 : colorBarCol2, :);
% Make sure they didn't mistakenly crop out some black bounding box around the colorbar.
[cbr, cbg, cbb] = imsplit(colorBarImage);
blackMask = (cbr == 0) & (cbg == 0) & (cbb == 0);
% Find rows and columns where all the pixels are pure black.
allBlackRows = all(blackMask, 2);
allBlackColumns = all(blackMask, 1);
% Delete all black columns:
colorBarImage(:, allBlackColumns, :) = [];
% Delete all black rows:
colorBarImage(allBlackRows, :, :) = [];
%=========================================================================================================
% Get the color map from the color bar image. Sometimes the images the users have are noisy JPG images
% with bad artifacts or dithering noise. Average across the colorbar to get the average colors.
[cbr, cbg, cbb] = imsplit(colorBarImage);
if size(cbr, 1) > size(cbr, 2)
% Colorbar has more rows than columns so it's vertical.
meanR = mean(cbr, 2); % Assumes vertical colorbar.
meanG = mean(cbg, 2); % Assumes vertical colorbar.
meanB = mean(cbb, 2); % Assumes vertical colorbar.
end1String = 'top'; % For the max temperature.
end2String = 'bottom'; % For the min temperature.
else
% Colorbar has more columns than rows so it's horizontal.
meanR = mean(cbr, 1); % Assumes horizontal colorbar.
meanG = mean(cbg, 1); % Assumes horizontal colorbar.
meanB = mean(cbb, 1); % Assumes horizontal colorbar.
end1String = 'right'; % For the max temperature.
end2String = 'left'; % For the min temperature.
end
% Also need to divide by 255 since colormap values must be between 0 and 1.
storedColorMap = [meanR(:), meanG(:), meanB(:)] / 255;
% Need to flip up/down because the low rows are the high temperatures, not the low temperatures.
storedColorMap = flipud(storedColorMap);
%========================================================================================================================================
% Now we need to define the temperatures at the end of the colored temperature scale.
% Ask them to do it here while the image is magnified to the full screen.
% You can read these off of the image, since we can't figure them out without doing OCR on the image.
% Define the temperature at the top end of the scale.
% This will probably be the high temperature.
highTemp = 31.6;
% Define the temperature at the dark end of the scale
% This will probably be the low temperature.
lowTemp = 20.6;
%========================================================================================================================================
% Optional : ask the user to confirm these two numbers.
% Ask user for two floating point numbers.
defaultValue = {sprintf('%.1f', highTemp), sprintf('%.1f', lowTemp)};
titleBar = 'Enter temperature range';
promptString1 = sprintf('Enter the temperature at the %s of the colorbar : ', end1String);
promptString2 = sprintf('Enter the temperature at the %s of the colorbar : ', end2String);
userPrompt = {promptString1, promptString2};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end % Bail out if they clicked Cancel.
% Convert to floating point from string.
highTemp = str2double(caUserInput{1});
lowTemp = str2double(caUserInput{2});
% Check highTemp for validity.
if isnan(highTemp)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue1.
highTemp = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', highTemp);
uiwait(warndlg(message));
end
% Do the same for lowTemp
% Check usersValue2 for validity.
if isnan(lowTemp)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue2.
lowTemp = str2double(defaultValue{2});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', lowTemp);
uiwait(warndlg(message));
end
% Display the original full image.
subplot(2, 3, 1);
imshow(originalRGBImage, []);
hFig.WindowState = 'maximized';
axis on;
caption = sprintf('Original Pseudocolor Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Put up a rectangle over the original image showing where we cropped out of.
rectanglePositionColorBar = [colorBarCol1, colorBarRow1, colorBarCol2 - colorBarCol1, colorBarRow2 - colorBarRow1];
hold on;
rectangle('Position', rectanglePosition, 'EdgeColor', 'r', 'LineWidth', 2);
rectangle('Position', rectanglePositionColorBar, 'EdgeColor', 'r', 'LineWidth', 2);
%=========================================================================================================
% Display the pseudocolored RGB image.
subplot(2, 3, 2);
imshow(rgbImage, []);
axis on;
caption = sprintf('Cropped Pseudocolor Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
% Display the colorbar image.
subplot(2, 3, 3);
imshow(colorBarImage, []);
axis on;
impixelinfo;
caption = sprintf('Cropped Colorbar Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Set up figure properties:
% Enlarge figure to full screen.
g = gcf;
g.WindowState = 'maximized';
% 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.
g.Name = 'Demo by ImageAnalyst';
g.NumberTitle = 'Off';
%=========================================================================================================
% Convert the subject/sample from a pseudocolored RGB image to a grayscale, indexed image.
indexedImage = rgb2ind(rgbImage, storedColorMap);
% Display the indexed image.
subplot(2, 3, 4);
imshow(indexedImage, []);
impixelinfo;
axis on;
caption = sprintf('Indexed Image (Gray Scale Thermal Image)');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
%========================================================================================================================================
% Scale the indexed gray scale image so that it's actual temperatures in degrees C instead of in gray scale indexes.
thermalImage = lowTemp + (highTemp - lowTemp) * mat2gray(indexedImage);
% Display the thermal image.
subplot(2, 3, 5);
imshow(thermalImage, []);
axis on;
colorbar;
title('Floating Point Thermal (Temperature) Image', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Column', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Row', 'FontSize', fontSize, 'Interpreter', 'None');
% Let user mouse around and see temperatures on the GUI under the temperature image.
hp = impixelinfo();
hp.Units = 'normalized';
hp.Position = [0.45, 0.03, 0.25, 0.02];
%=========================================================================================================
% Get and display the histogram of the thermal image.
subplot(2, 3, 6);
histogram(thermalImage, 'Normalization', 'probability');
axis on;
grid on;
caption = sprintf('Histogram of Temperatures in Thermal Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Temperature [Degrees]', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Frequency [Pixel Count]', 'FontSize', fontSize, 'Interpreter', 'None');
% Get the maximum temperature.
maxTemperature = max(thermalImage(:));
fprintf('The maximum temperature in the image is %.2f\n', maxTemperature);
fprintf('Done! Thanks Image Analyst!\n');
%%%%%%%%%%%%%%%% END OF MAIN PROGRAM %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%===============================================================================================================================
% Function to have the user draw a box around some part of the image.
% You pass in what part you're asking for in the userPrompt string.
function roiPosition = GetRectangularROI(userPrompt)
roiPosition = [];
hRect = [];
% Ask user to draw rectangle.
button = 'Redraw';
while contains(button, 'Redraw', 'IgnoreCase',true)
uiwait(helpdlg(userPrompt));
% User draws a box. It exits as soon as they lift the mouse.
hBox = drawrectangle('Color', 'r');
% Get the coordinates in the form [xLeft, yTop, width, height].
roiPosition = hBox.Position;
% Delete the ROI object.
delete(hBox);
% and replace it with a rectangle in the graphical overlay.
hold on;
hRect = rectangle('Position', roiPosition, 'EdgeColor', 'r', 'LineWidth', 2);
% Ask user if the rectangle is acceptable.
message = sprintf('Is this good?');
button = questdlg(message, message, 'Accept', 'Redraw', 'Reject and Quit', 'Accept');
if contains(button, 'Quit','IgnoreCase',true)
delete(hRect); % Delete the box from the overlay.
roiPosition = [];
break;
elseif contains(button, 'Redraw','IgnoreCase',true)
% OPTIONAL If you want to delete the prior one before drawing the next one.
delete(hRect);
elseif contains(button, 'Accept','IgnoreCase',true)
break;
end
end
% If you want to delete the rectangle from the overlay, do this:
% delete(hRect); % Delete the box from the overlay.
end
I have used the same code provided here but I didnt get the expected output.All I got is the input image I have given.I am fairly new to matlab and thermal image processing and not sure how to proceed with cropping color bar and image.Kindly help me with the same.

Image Analyst
el 4 de Mzo. de 2023
See my latest version, attached.
Tasneem
el 31 de Mayo de 2023
Sorry to bother you and thank you for your demo above.
I am new to Matlab and coding.
I am working on a project looking at the use of thermal imaging.
I was wondering if you could help me with how to define an area of interest in the image to calculate the mean temperature (excluding the background) and use this to define an isotherm area.
Is it then possible to subtract this to view areas above this mean temperature?
Thank you!
If there are video tutorials I could be directed to I would be very grateful
BW
Image Analyst
el 31 de Mayo de 2023
oneTemperature = temperatureImage == desiredTemperature; % Makes a binary image.
To specify an ROI, you can do it in several ways, such as by thresholding.
hotPixels = temperatureImage > someTemperature;
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
If you have more questions, start a new discussion thread of your own and attach your image(s).
Tasneem
el 31 de Mayo de 2023
I will have a look and try get my head around it.
I will start my own thread as well
thank you for your help and time!
Güney Can Gürbüz
el 5 de Jun. de 2023
0 votos
Dear @Image Analyst , I have a task which is related image processing. I need to see temperatures along a horizontal line where is center of the circles. Could you help me about this problem? How can I see temperature vs position graph? Thank you in advance.
8 comentarios
The process is the same as above, just use improfile() on the thermal data. In order to do that, use an image that's not full of annotations, because you can only guess what data is obscured by annotations.
% read the image
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1403674/11.jpg');
% extract a color table from the colorbar
CT0 = imcrop(inpict,[603.5 71.5 17.9 337.9]);
CT0 = im2double(CT0); % unit scale float
CT0 = mean(CT0,2); % average rows
CT0 = flipud(permute(CT0,[1 3 2])); % reorient
% estimate data from the pseudocolor image
cblimits = [51 73]; % from the picture
thermalpict = rgb2ind(inpict,CT0); % apply the color table
thermalpict = interp1([0 size(CT0,1)],cblimits, ...
double(thermalpict),'linear'); % rescale
% show the image
imshow(thermalpict,[])
% manually select some profile
npoints = 100;
tprofile = improfile(npoints);
plot(tprofile)

Güney Can Gürbüz
el 6 de Jun. de 2023
Thank you so much for your help dear @DGM
Güney Can Gürbüz
el 6 de Jun. de 2023
Editada: Güney Can Gürbüz
el 6 de Jun. de 2023
I'm sory for bothering you dear @DGM and @Image Analyst, This task about my final thesis and I need to make this graph asap. Also, I have a question. Is this process could be adapted to video? If you help me, I appreciate you.
Image Analyst
el 6 de Jun. de 2023
@Güney Can Gürbüz it seems to work fine. Did you try to adapt it? You would have gotten the attached.

DGM
el 6 de Jun. de 2023
If you check the documentation for improfile(), you should be able to get the query points from a given manual selection and apply those to other frames. Bear in mind though, if the colorbar scale changes over time, the temperature calculations will be wrong. Could you use OCR to read the colorbar limits for each frame? Maybe, but I don't have OCR tools to test that with.
NUZUL
el 10 de En. de 2024
Hello sir,can you help me i want to use it for my study but i need to use the Iron colourmap(pallette) for my image segmentation can you help me how to set it up
It's not clear what your task is, whether you're talking about trying to use improfile(), or what to part of the task the colormap is relevant.
There are a handful of "iron" colormaps that are all very similar but not identical, and I don't know of any which I would consider to be canonical. For example, the map used above is what many sources would refer to as "iron", even though it's significantly different to both the FLIR and Chauvin-Arnoux maps. Some of the maps you might find online that are claimed specifically to be a duplicate of the FLIR map are even less accurate. As far as I know, there are at least two distinct "iron" map variants used by FLIR.
Here is a handful of maps which are either explicitly called "iron" or are claimed specifically to be the FLIR map, or are recommended as being a substitute:

If the goal is to estimate temperature from pseudocolor images, then getting an accurate estimate of the applied colormap is essential. Given the above sample, "iron" is not specific enough to be useful.
Click the Ask button at the top of the page and write a question describing your task. If there are relevant images, include them. If it's not apparent from the images, mention the camera brand.
Image Analyst
el 10 de En. de 2024
@NUZUL, colormaps are not used for image segmentation.
If you're talking about my thermal image demo above, it does not matter what colorbar/colormap is embedded in the thermal image. It will work with any colormap.
If you're wanting to create an "iron" colormap, then you'll have to define it because it's not one of the built-in colormaps of MATLAB.
To define your own:
>> colormapeditor
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






