counting holes in an image

22 Ansichten (letzte 30 Tage)
Pamela Huntley
Pamela Huntley am 26 Mär. 2020
Beantwortet: Image Analyst am 27 Mär. 2020
writing an algorithm that will count the number of holes in the image that do not touch the border

Akzeptierte Antwort

Image Analyst
Image Analyst am 27 Mär. 2020
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);

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 26 Mär. 2020
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.

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by