counting holes in an image

조회 수: 16 (최근 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 CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by