Réponse acceptée

Image Analyst
Image Analyst le 27 Mar 2020

0 votes

Threshold then call imclearborder() and bwlabel(). Assuming you have dark holes on a bright background:
% Binarize:
binaryImage = grayImage < someValue;
% Remove those touching border
binaryImage = imclearborder(binaryImage);
% Count holes:
[~, numHoles] = bwlabel(binaryImage);

Plus de réponses (1)

Walter Roberson
Walter Roberson le 26 Mar 2020

0 votes

Invert the image so the holes become solid and the solid gets removed. Remove from that all solid touching the border -- those correspond to holes that were touching the border in the original. Now count the number of solid objects remaining, and that will be the number of holes in the original.

Community Treasure Hunt

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

Start Hunting!

Translated by