Clear Filters
Clear Filters

problem with determining the area of an object in a binary image

3 views (last 30 days)
I am trying to calculate the area of a fire spreading over an area. I have frames with different time steps. I process an infrared image and convert it to a binary image. However, when I calculate the burned area, which should bigger with the advance in time, I get a smaller area from a specific time step to another. I use the function "bwarea" to calculate the area that has pixels "on". I am attaching here the two binary images with the boundary of the objects (burned area), where it's clear that the area on frame 2 is bigger than frame 1, but the results of "bwarea" shows an area of ~2300 for frame 2 and ~2800 for frame 1
Frame 1:
Just to eliminate the possibilities:
  • there is more than one object in the image >> I am sure I am considering the correct object (the biggest one)
  • The two image have exactly the same size and resolution
Any ideas please why this is happening?
Here is part of the code as well
BI{i} = imclose(BI{i},strel('disk',6));
BI{i} = imfill(BI{i},'holes');
BI{i}(MaskROI == 0) = 0;
BI{i} = imclose(BI{i},strel('disk',6));
BI{i} = imfill(BI{i},'holes');
BI{i}(MaskROI == 0) = 0;
[Bn,L,N] = bwboundaries(BI{i},'noholes',8);
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(Bn)
boundary = Bn{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
hold off
for s=1:N

Accepted Answer

Image Analyst
Image Analyst on 8 Apr 2019
If you want all the areas, use regionprops():
props = regionprops(binaryImage, 'Area');
allAreas = [props.Area]
totalArea = sum(allAreas);
Or you can just sum your binary image
totalArea = sum(binaryImage(:))
If you want more help, attach your two original binary images (not pseudocolored RGB images).

More Answers (1)

Clay Swackhamer
Clay Swackhamer on 8 Apr 2019
You could try running the same code, except instead of using bwarea you could try summing all the pixels in the image. Since in the binary image you can make the pixels representing fire either 1 or 0 you can directly calculate area based on their sum. Here is an example to show you what I mean.
I = imread('rice.png');
Ibw = imbinarize(I);
areaRice = sum(sum(Ibw))
This assumes that all of your pixels are equal area, but you get the gist.
Not sure if that works for ya but it could be worth a try.


Find more on Convert Image Type in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!