Reputation: 23
I have a binary image from which I want to measure the area of connected white region manually, without using MATLAB functions. I have labeled the regions
I=imread('https://i.sstatic.net/rBaua.jpg')
[Label,Total]=bwlabel(I,8);
The Label is <669x585 double> variable that has all the connected white area labeled separately, starting from 1:Total. Here is the image:
.
Upvotes: 2
Views: 100
Reputation: 65460
If you don't want to use any built-in functions, you can easily loop through the labels and compute the number of pixels with a given label.
areas = arrayfun(@(x)sum(Label(:) == x), 1:max(Label(:)));
Alternately, you could use something like accumarray
or histcounts
to count them for you.
areas = accumarray(Label(:)+1, Label(:), [], @numel);
areas = histcounts(Label(:), 1:max(Label(:)));
Upvotes: 1