MATLAB Answers

I have segmented a image using region growing. Now i want to count number of pixels in each regions. How can i do that?

2 views (last 30 days)
Purbankan
Purbankan on 20 Jun 2014
Commented: Image Analyst on 14 May 2021
I have segmented a image using region growing. Now i want to count number of pixels in each regions. How can i do that? i want all the regions which have less than 100 pixels.

Answers (1)

Image Analyst
Image Analyst on 20 Jun 2014
% Extract only small blobs:
bigBlobs = bwareaopen(binaryImage, 100);
smallBlobs = binaryImage - bigBlobs;
% Measure areas
labeledImage = bwlabel(smallBlobs);
measurements = regionprops(labeledImage, 'Area');
allAreas = [measurements.Area]
  2 Comments
Image Analyst
Image Analyst on 14 May 2021
The regionprops() function is the part that counts all the pixels in each region.
allAreas is a vector that counts the number of pixels in each region. For example if your mask had two regions with 12000 and 25000 pixels, then allAreas would be [12000, 25000]
I am measuring areas because area has units of pixels and the area is the count of the number of pixels in the region.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!