Clear Filters
Clear Filters

calculated HSV and their mean (highest and lowest values) and std deviation of 120 (same resolution) fire images.now want to detect fire from random random images by specifying high and low values of HSV.i get all values of tht within ranges. plzhelp

3 views (last 30 days)
rgbImage= imread('fire-image5.jpg'); % read the image
hsvImage=rgb2hsv(rgbImage);
h =hsvImage(:,:,1);
mh1=mean2(h);
rgbImage= imread('fire-image5.jpg'); % read the image
hsvImage=rgb2hsv(rgbImage);
s=hsvImage(:,:,2);
ms1=mean2(s);
rgbImage= imread('fire-image5.jpg'); % read the image
hsvImage=rgb2hsv(rgbImage);
v =hsvImage(:,:,3);
mv1=mean2(v);
//now detecting fire from the random image of the same resolution.//
rgbImage= imread('testfire-image10.jpg'); % read the image
hsvImage=rgb2hsv(rgbImage);
h =hsvImage(:,:,1);
mh1=mean2(h);
minVal_h= 0.0176;
maxVal_h = 0.3682;
if (mh1 >= minVal_h) && (mh1 <= maxVal_h)
disp('H mean Value within specified range.')
elseif (mh1 > maxVal_h)
disp('H mean Value exceeds maximum value.')
else
disp('H mean Value is below minimum value.')
end
s=hsvImage(:,:,2); ms1=mean2(s);
minVal_s= 0.0467; maxVal_s = 0.9421;
if (ms1 >= minVal_s) && (ms1 <= maxVal_s)
disp('S mean Value within specified range.')
elseif (ms1 > maxVal_s)
disp('S mean Value exceeds maximum value.')
else
disp('S mean Value is below minimum value.')
end
s=hsvImage(:,:,3); mv1=mean2(s);
minVal_V= 0.0674; maxVal_V = 0.4738;
if (mv1 >= minVal_V) && (mv1 <= maxVal_V)
disp('V mean Value within specified range.')
elseif (mv1 > maxVal_V)
disp('V mean Value exceeds maximum value.')
else
disp('V mean Value is below minimum value.')
end

Answers (3)

Fahad Mairaj
Fahad Mairaj on 8 Sep 2018
i have checked 10 random non-fire images of same resolution but passed only 3 images as non fired. plz suggest.

Image Analyst
Image Analyst on 8 Sep 2018
Are you serious about detecting fire? If so, check out the papers that have already done it:
They will show you effective methods where people have done this in the real world with actual fire imagery.
Or, if it's just a practice program for you while you learn how to do color segmentation, then try using the Color Thresholder on the Apps tab of the tool ribbon.

Guillaume
Guillaume on 11 Sep 2018
Can I differentiate fire images from non-fire images comparing the values of the mean of HSV values
No, not reliably. You may be able to have some limited success with the mean of the Hue, i.e. you'll be able to say that image is predominantly orange, or yellow, or red but that's it. It certainly doesn't cover all types of fire and will identify non-fire images as fire.
As for the Saturation and Luminance channels, their mean will only tell you how vivid and bright the whole image is. Something that is mostly unrelated to whether or not the image is fire. The fact that you are even attempting to do that would indicate that you don't really understand what the 3 channels represent in the HSV colour space, so I'd suggest you read up on that.
You also need to think better about the code you write. You certainly like to do the same task over and over for no reason. Your algorithm starts with:
  1. read image (as RGB)
  2. convert image to HSV
  3. extract hue and calculate mean
  4. read again the same image that is already in memory
  5. convert to the same HSV image that is already in memory
  6. extract saturation and calculate mean
  7. again waste time reading the image that we've already read twice and still have in memory
  8. again waste time converting to HSV for the third time when we still have the result in memory
  9. extract value and calculate mean
  3 Comments
Guillaume
Guillaume on 11 Sep 2018
Yes, that is better code.
However, the first part of my answer still stand. Relying on the Hue is not enough to reliably differentiate between fire and non-fire images. Saturation and luminance would be even less useful.
For example, the image below has the exact same mean Hue, Saturation and Luminance as your fire-image5.
Image Analyst
Image Analyst on 11 Sep 2018
Edited: Image Analyst on 11 Sep 2018
Using HSV would only work for very specific type of images, not for any fire image in general, like if you were looking at your backyard firepit and had only photos of no fire, or fire. Then you could have a reference gamut that you could compare the test gamut against. If you just had general fire images, then I suggest you try deep learning.
The image below has the very same histograms (mean, std dev, and all higher moments), in both RGB and HSV, as your original image because I just scrambled it (rearranged pixels) with the attached demo. Would you call it fire?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!