problem with determining the area of an object in a binary image
1 次查看(过去 30 天)
显示 更早的评论
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');
BI{i}(MaskROI == 0) = 0;
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');
BI{i}(MaskROI == 0) = 0;
[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
0 个评论
采纳的回答
Image Analyst
2019-4-8
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 个)
Clay Swackhamer
2019-4-8
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');
imshow(I)
Ibw = imbinarize(I);
imshow(Ibw)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!