fill holes on BW image with bwconncomp and labelmatrix

조회 수: 3 (최근 30일)
Alex Dashevsky
Alex Dashevsky 2017년 5월 20일
댓글: Walter Roberson 2017년 5월 21일
How can I fill holes on BW image with bwconncomp and labelmatrix without imfill. Give me simple example ,please. for example, I want to fill the star with white.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 5월 20일
x = checkerboard(20,3,5);
y = x;y(rand(size(x))<.3) = 0;
labelmatrix = bwlabel(y);
to_fill = imclearborder(labelmatrix==0, 4);
[~, idx] = bwdist(labelmatrix ~= 0);
filled_label_matrix = labelmatrix;
filled_label_matrix(to_fill) = labelmatrix(idx(to_fill));
subplot(1,2,1); imagesc(labelmatrix);
subplot(1,2,2); imagesc(filled_label_matrix);
Note: for this purpose I defined "hole" in terms of 4 connectivity: with the default 8 connectivity, diagonal empty blocks were considered reachable from each other. You should try both ways and see which is better for your purpose.
  댓글 수: 4
Alex Dashevsky
Alex Dashevsky 2017년 5월 21일
Please, help me. It is very intresting for me.
Walter Roberson
Walter Roberson 2017년 5월 21일
Call bwconncomp and throw the result away.
... Or explain why bwconncomp() must be used and imfill() must not be used.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by