MATLAB Answers

How to count the number of object present in binary image?

286 views (last 30 days)
Hanuman Wable
Hanuman Wable on 20 Dec 2013
Commented: Image Analyst on 7 Nov 2018
Hello sir, i am going to count the number of object present in binary image. so any of you please suggest me regarding counting object.because i have problem during count such object. thank you

Answers (4)

Sabarinathan Vadivelu
Sabarinathan Vadivelu on 20 Dec 2013
Edited: Sabarinathan Vadivelu on 20 Dec 2013
You can use bwconncomp.
cc = bwconncomp(yourBinaryImage,4);
number = cc.NumObjects;

Image Analyst
Image Analyst on 20 Dec 2013
Here's yet another way
[labeledImage, numberOfObject] = bwlabel(binaryImage);
  3 Comments

Sign in to comment.


David Sanchez
David Sanchez on 20 Dec 2013
If you are planning to do something with those objects, you could be interested in using regionprops. Besides the number of objects within the image, you can retrieve any other property of the objects, such as the area, centroid, orientation,....
BW = imread('text.png');
s = regionprops(BW, 'Area');
N_objects = numel(C);
For all the options, take a look at
doc regionprops
  2 Comments
Image Analyst
Image Analyst on 7 Nov 2018
I don't know what you want. By the way, the code above is not correct. It should say
N_objects = length(s)
That number will be the same regardless which attributes you measure (area, perimeter, or whatever).

Sign in to comment.


sanhita das
sanhita das on 7 Apr 2018
sir,i want to show paragraphs from document image.pls tell the algoritm name. I attach a input file.and how to extract paragraph from this image.please help me

Community Treasure Hunt

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

Start Hunting!