does the grayscale image always give the temperature value corresponding to thermal image?

 Réponse acceptée

All you had to do was to take my demo and give the right coordinates for your image and your colorbar, and assign the colorbar limits - easy. Try this:
% 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.
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 = 'ir_girl.png'; % Base file name with no folder prepended (yet).
% 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)
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.
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.
%=========================================================================================================
% Need to crop out the image and the color bar separately.
% First crop out the image.
imageRow1 = 1;
imageRow2 = size(originalRGBImage, 1);
imageCol1 = 1;
imageCol2 = 969;
% 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.
colorBarRow1 = 64;
colorBarRow2 = 757;
colorBarCol1 = 986;
colorBarCol2 = 1075;
hold on;
rectangle('Position', [colorBarCol1, colorBarRow1, colorBarCol2-colorBarCol1, colorBarRow2-colorBarRow1], 'EdgeColor', 'b');
hold off;
% Crop off the surrounding clutter to get the colorbar.
colorBarImage = originalRGBImage(colorBarRow1 : colorBarRow2, colorBarCol1 : colorBarCol2, :);
b = colorBarImage(:,:,3);
%=========================================================================================================
% 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;
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.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
%=========================================================================================================
% Get the color map from the color bar image.
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 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, []);
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;
%=========================================================================================================
% Now we need to define the temperatures at the end of the colored temperature scale.
% 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 = 42;
% Define the temperature at the dark end of the scale
% This will probably be the low temperature.
lowTemp = 22;
% 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.05];
%=========================================================================================================
% 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 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');

6 commentaires

Thank you sir.
Sir Is there any other method to analyse the thermal image or write a code in MATLAB?
Yes, an infinite amount of them. Do you want to know them all?
Or do you want to do some specific thing, like find the mean temperature of some region, or find out if there are any regions hotter than some temperature? If so, what specifically do you want to know about that image?
Sir the one you have done above in the gray scale ..in the similar manner finding the temperature of each pixel at particular region or the selected region but with different approach...I need at least 3-4 different approaches.I tried using image segmentation but it's not working. Can you help me in this?
Not sure what you're asking. I converted a pseudocolor image into a monochrome temperature image using the supplied colormap. I don't know of any other way to so it. I don't know what you did with segmentation -- I really don't see how that applies here unless you wanted to segment out the faces or something (which you have not requested). Why do you need 3-4 different ways of converting the color image into a temperature image??
Thank you sir for your reply.Sir If there is no color map in the image .If it is a thermal image in jpg only without color map...Will it be possible to use above method and then in that case will there be any other method.?
I = randi([0 255], 32, 32, 'uint8');
directions = {'ascend', 'descend'};
cmaps = {@jet, @parula};
for K = 1 : 2
d = directions{randi(2)};
m = randperm(2);
II = I;
for n = m
II = sort(II, n, d);
end
cmap = cmaps{randi(2)}();
cmap = cmap(randperm(size(cmap,1)),:);
figure
image(II); colormap(cmap);
end
So... what are the temperatures on these two images?
I constructed these images in such a way that one of the corners is the hotest part of the image. But which corner? Can you tell from the color? Can you tell me how hot it is?
OKay, try this:
This is a thermal image. What is the temperature range shown here?

Connectez-vous pour commenter.

Plus de réponses (2)

Walter Roberson
Walter Roberson le 16 Juin 2021
Modifié(e) : Walter Roberson le 16 Juin 2021
No, not at all.
Consumer thermal cameras often use a color map in which increased temperature is not mapped to increase brightness.
For example, it is common for high temperature to be represented as bright red, and for blue to be comparatively cool, but the reality in temperature is that red is on the cooler side and that blue is on the hotter side. Infrared (red side) has less energy than ultra-violet (blue side), but humans do not see ultraviolet well. Humans are most receptive to Green, but you never see consumer cameras represent heat as bright green!
It is possible to create a color scale in which brightness increases across the scale. The parula color scale attempts to do that. But it is not what consumer cameras usually use.
Because of this, if you convert consumer thermal camera color images to grayscale, it is common not to be able to just take the luminance as being proportional to temperature; you usually have to use a non-linear mapping.

6 commentaires

Thank you sir for your reply. Sir I am attaching a code and its output , the 5th figure (floating point temperature)in the output the color scale on the right side shows the opposite result as where the temperature should be low it represents high and vice versa.
Sir can you help me in the code part ?
Attach Ir_girl.png so that we can run the code.
I suspect the code to detect the colorbar is broken.
The code you are using expects the colorbar to be over to the left, but the image you are using has the colorbar to the right, over near column 1000.
The image you attached is not a valid PNG image, or at least MATLAB can't read it:
Error using imread>get_format_info (line 545)
Unable to determine the file format.
Error in imread/call_format_specific_reader (line 466)
fmt_s = get_format_info(fullname);
Error in imread (line 440)
[X, map] = call_format_specific_reader();
Error in test3 (line 25)
originalRGBImage = imread(fullFileName);
Please attach an image that MATLAB can read in.

Connectez-vous pour commenter.

Sir can we detect temperature of thermal image using Image segmentation?

13 commentaires

No, you cannot detect temperature in thermal images using image segmentation.
Why did you accept this answer?
I am not sure about segmentation to detect temperature that is why I did ...even I tried one example in MATLAB but its not giving me results as my image is in png an in this it is in tif..I do not know does that make any diffrence? I tried following method methos but its giving me only original image.
clc;
close all;
clear;
workspace;
I = imread('Ir_girl.png');
whos I
max=42;
min=22;
range = [max-min];
figure
imshow(I,[])
colormap(gca,hot)
title('Original image')
smoothValue = 0.01*diff(range).^2;
J = imguidedfilter(I,'DegreeOfSmoothing',smoothValue);
figure
imshow(J,[])
colormap(gca,hot)
title('Guided filtered image')
thresh = multithresh(J,2)
L = imquantize(J,thresh);
L = imfill(L);
figure
imshow(label2rgb(L))
title('Label matrix from 3-level Otsu')
props = regionprops(L,I,{'Area','BoundingBox','MeanIntensity','Centroid'});
% Find the index of the background region.
[~,idx] = max([props.Area]);
figure
imshow(I,[])
colormap(gca,hot)
title('Segmented regions with mean temperature')
for n = 1:numel(props)
% If the region is not background
if n ~= idx
% Draw bounding box around region
rectangle('Position',props(n).BoundingBox,'EdgeColor','c')
% Draw text displaying mean temperature in Celsius
T = [num2str(props(n).MeanIntensity,3) ' \circ C'];
text(props(n).Centroid(1),props(n).Centroid(2),T,...
'Color','c','FontSize',12)
end
end
ERRORS
Error using imguidedfilter>parse_inputs (line 143)
The value of 'DegreeOfSmoothing' is invalid. Expected DegreeOfSmoothing to be nonempty.
Error in imguidedfilter (line 116)
[A, G, filtSize, inversionEpsilon] = parse_inputs(varargin{:});
Error in d (line 15)
J = imguidedfilter(I,'DegreeOfSmoothing',smoothValue);
Can you suggest some methods?
done the above mentioned change but still having errors
Error using label2rgb
Expected input number 1, L, to be two-dimensional.
Error in label2rgb>parse_inputs (line 142)
validateattributes(L,{'numeric','logical','categorical'}, attributes, mfilename,'L',1);
Error in label2rgb (line 58)
[label,map,zerocolor,order,fcnflag] = parse_inputs(args{:});
Error in d (line 24)
imshow(label2rgb(L))
You are passing an rgb image to a function that is expecting a 2d label image.
You are not converting your rgb image into grayscale at any time.
Note: doing image segmentation could potentially help you identify what portion of the image is the colormap.
I = imread('hotcoffee.tif');
whos I
Name Size Bytes Class Attributes
I 240x320 30720
Notice that I only has two dimensions. It is a grayscale image.
thank you sir for your reply ... the errors are reduced but still got following error
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
Error in s1 (line 33)
[~,idx] = max([props.Area]);
sir I am facing error in setting the range and the threshold value?
Can you help me in this part?
As range returns the pixel value 0- 255 not the temperature value

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by