how to remove background from thermal image. i want to remove the background from the image. just want forground image

6 views (last 30 days)
  1 Comment
DGM
DGM on 22 Jul 2024
Edited: DGM on 22 Jul 2024
Like Walter mentions, the distinction between "background" and "foreground" depends on context. Sometimes the features in the image are salient enough that we might be able to guess, but in this case, it's not at all clear.
Is the distinction spatial? If so, where is the boundary? Does the boundary change between images?
Is the distinction a matter of some specific temperature? If so, we'd need more information than a pseudocolor image alone.

Sign in to comment.

Answers (4)

Walter Roberson
Walter Roberson on 21 Jul 2024
Consider the thermal images of the Parker Solar Probe. The standard operation of the probe is to block out the main disk of the Sun, and record the prominences of the edge of the Sun.
However, a secondary operation of the probe is to ignore the solar disk and the prominences, and look for moving objects -- to search for comets!
Exactly the same image is being used each time, but the interest is shifted. What is foreground for one purpose is background for the other purpose, and likewise what is background for one purpose is foreground for the other purpose.
It follows that it is impossible to automatically filter out background -- because background for one purpose might be foreground for a different purpose. It is impossible to distinguish foreground and background based entirely on the features of an image.

Amith
Amith on 21 Jul 2024
Hi Ashvini,
There are several methods to remove a background. You might find this resource helpful:
For more information on this topic, you can refer to a previously answered question on MATLAB Answers:
Hope this helps!

Image Analyst
Image Analyst on 22 Jul 2024
The first question is why do you want to remove the background? Chances are you don't need to "remove" it but that you just need to define a region of interest mask to say what's the region you're not interested in, and what's the region you're interested in.
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.
There is also a thermal image demo there where you can convert an RGB image into an image where the pixel values are the actual temperature in degrees. https://www.mathworks.com/matlabcentral/fileexchange/113995-thermal-image-color-to-temperature?s_tid=srchtitle
The next question is do you have the raw data (values in units of temperature degrees), or do you just have the RGB pseudocolored image. If you have a colorbar you can convert the pseudocolored image into a temperature image. If you don't you can "blacken" the reddish/pinkish background by starting out with the Color Thresholder on the Apps tab of the tool ribbon and then cleaning up with some morphological operations like bwareafilt, imfill, imclearborder, and functions like that.
If you still need more help, reply with answers to the several questions I asked you.

Image Analyst
Image Analyst on 24 Jul 2024
Again, I don't think you need to actually zero out (blacken/remove) the background, but this is what you asked for:
% Demo by Image Analyst
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 = 16;
markerSize = 20;
%--------------------------------------------------------------------------------------------------------
% READ IN TEST IMAGE
folder = [];
baseFileName = 'Thermal_imageRGB.jpeg';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
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
rgbImage = imread(fullFileName);
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 1);
imshow(rgbImage, []);
impixelinfo;
axis('on', 'image');
title('Original RGB Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Update the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
rows = 960
columns = 1280
numberOfColorChannels = 3
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
g.Name = 'Demo by Image Analyst';
g.NumberTitle = 'off';
drawnow;
%--------------------------------------------------------------------------------------------
% MASK THE IMAGE.
[mask,maskedRGBImage] = createMask(rgbImage);
% Take the largest blob.
mask = bwareafilt(mask, 1);
subplot(2, 2, 2);
imshow(mask)
impixelinfo;
axis('on', 'image');
title('Foreground Pixels', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Mask the image with the new mask by multiplying each channel by the mask.
maskedRgbImage = rgbImage .* cast(mask, 'like', rgbImage); % R2016b or later. Works for gray scale as well as RGB Color images.
% Show the masked image.
subplot(2, 2, 3);
imshow(maskedRgbImage)
impixelinfo;
axis('on', 'image');
title('Masked RGB Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
%=================================================================================================================
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 24-Jul-2024
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.052;
channel1Max = 0.932;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end

Community Treasure Hunt

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

Start Hunting!