Count amount of contours in images

5 vues (au cours des 30 derniers jours)
Guy Talmor
Guy Talmor le 12 Avr 2015
Commenté : Siti Aisyah le 21 Avr 2016
I am struggling to find a good contour detection function that would count the number of contour in bw images that I have processed using some previous tools. I have uploaded an example of such image. In this image, ideally, I wish to have a function which counts four closed contour.
I don't mind if it also detects the really tiny contours in between, or the entire shape itself as extra contours. As long as it counts the medium sized ones, I can fix the rest by applying area threshold. My problem is that any function I have tried detects only one contour - the entire shape, as it cannot separate it to the su-conours which are connected to one another.
Any suggestions?

Réponse acceptée

Image Analyst
Image Analyst le 12 Avr 2015
Very very easy
% Invert and get rid of the border.
binaryImage = imclearborder(binaryImage);
% Count the number of blobs:
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
Actually it looks like there are around 10 or so. If you want to remove blobs smaller than, say 500 pixels, add a call to bwareaopen():
% Invert and get rid of the border.
binaryImage = imclearborder(binaryImage);
% Get rid of blobs smaller than 500 pixels.
binaryImage = bwareaopen(binaryImage, 500);
% Count the number of blobs:
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
  5 commentaires
Guy Talmor
Guy Talmor le 12 Avr 2015
Excellent! it works.
Thank you
Siti Aisyah
Siti Aisyah le 21 Avr 2016
Could you help me on how to do the filtering on Figure A like how the person do in figure B? the are that I want is the one i highlighted in figure C. I have set of images as in figure A with different size and area of the interested region

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by