counting holes in an image

22 ビュー (過去 30 日間)
Pamela Huntley
Pamela Huntley 2020 年 3 月 26 日
回答済み: Image Analyst 2020 年 3 月 27 日
writing an algorithm that will count the number of holes in the image that do not touch the border

採用された回答

Image Analyst
Image Analyst 2020 年 3 月 27 日
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);

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 3 月 26 日
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.

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by