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

### Abdelrahman Abouali (view profile)

on 7 Apr 2019
Latest activity Commented on by Abdelrahman Abouali

on 15 Apr 2019

### Image Analyst (view profile)

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:
Frame2:
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');
diff=abs(BI{i}-BI{i-1});
BI{i}=BI{i-1}+diff;
BI{i} = imclose(BI{i},strel('disk',6));
BI{i} = imfill(BI{i},'holes');
[Bn,L,N] = bwboundaries(BI{i},'noholes',8);
figure;
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)
end
hold off
SizeDetFires=zeros(1,N);
for s=1:N
SizeDetFires(1,s)=bwarea(Bn{s,1});
end

R2018a

### Image Analyst (view profile)

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).

#### 1 Comment

Abdelrahman Abouali

### Abdelrahman Abouali (view profile)

on 15 Apr 2019
Thanks, it works, but in fact I used "polyarea" and it worked just fine for me

### Clay Swackhamer (view profile)

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.