Need help isolating the flame in an image.

I was wondering what method would be the best way to accurately extract a flame from an image with a lot of noise/background?

 Akzeptierte Antwort

Image Analyst
Image Analyst am 8 Jul. 2013

0 Stimmen

I'd use either intensity thresholding or color segmentation. Where did you upload your image?

11 Kommentare

Terry Huang
Terry Huang am 10 Jul. 2013
Is there an email which I could send and show you the image I am attempting to isolate?
Image Analyst
Image Analyst am 10 Jul. 2013
No. But you can upload to http://snag.gy
Terry Huang
Terry Huang am 12 Jul. 2013
Sorry about the late replies, I've been super busy but the link below would be an example of a flame I am trying to isolate.
Image Analyst
Image Analyst am 12 Jul. 2013
Bearbeitet: Image Analyst am 12 Jul. 2013
Start off by thresholding:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
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;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\Terry\Documents\Temporary';
baseFileName = 'SdU5k.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, '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);
% Display the original color image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 1); % Take red channel.
end
% Display the original color image.
subplot(2, 2, 2);
imshow(grayImage, []);
title('Red Channel Image', 'FontSize', fontSize);
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
subplot(2, 2, 3);
bar(pixelCount);
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Now get some threshold for noise
meanGL = mean(grayImage(:))
sd = std(double(grayImage(:)))
thresholdValue = meanGL + 1.1 * sd
% Threshold the image to find noise.
noisePixels = grayImage >= thresholdValue;
% Display the noise pixels.
subplot(2, 2, 4);
imshow(noisePixels, []);
caption = sprintf('Pixels above Threshold of %.2f', thresholdValue);
title(caption, 'FontSize', fontSize);
Terry Huang
Terry Huang am 18 Jul. 2013
Bearbeitet: Terry Huang am 18 Jul. 2013
AWESOME, this was very helpful, is it better to let the program or the user determine the threshold
Image Analyst
Image Analyst am 18 Jul. 2013
If you don't have hundreds of images, I'd let the user do it. See my file exchange for a nice interactive thresholding GUI.
Terry Huang
Terry Huang am 18 Jul. 2013
Bearbeitet: Terry Huang am 18 Jul. 2013
I have 1335 frames of flames By the way thanks again for your help, this has made my project way easier
Image Analyst
Image Analyst am 18 Jul. 2013
Then you might try inventing some kind of auto-thresholding method. Chances are that the built-in bwthresh() will not do a robust job and you'll have to tweak your own custom method.
Terry Huang
Terry Huang am 18 Jul. 2013
also could you explain this line alittle: thresholdValue = meanGL + 1.1 * sd;
Image Analyst
Image Analyst am 19 Jul. 2013
It just thresholds the image at 1.1 standard deviations above the mean gray level.
Terry Huang
Terry Huang am 19 Jul. 2013
Gotcha, I noticed in the segmented picture (the one that's black and white) there is still some noise to the right of the flame. Is there any way to get rid of this noise because I will be wanting to track the right and left most points of the flame.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by