Displaying objects found with bwconncomp

조회 수: 5(최근 30일)
Ivan Aguilar
Ivan Aguilar 2021년 10월 11일
답변: DGM 2021년 10월 11일
I have found the amount of objects in my binary image, but I am not sure how to display those objects.
  댓글 수: 2
Ivan Aguilar
Ivan Aguilar 2021년 10월 11일
Not all components, just two, the two that have the maximum and minimum areas.

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

답변(1개)

DGM
DGM 2021년 10월 11일
I never really use bwconncomp, but I guess you could do something like this.
% create test image
A = imread('coins.png') > 80;
A = bwareaopen(A,100);
imshow(A)
% find min/max blob areas
C = bwconncomp(A);
area = cell2mat(cellfun(@numel,C.PixelIdxList,'uniform',false));
[~,mnidx] = min(area);
[~,mxidx] = max(area);
% construct the two images
smallblob = false(size(A));
smallblob(C.PixelIdxList{mnidx}) = true;
largeblob = false(size(A));
largeblob(C.PixelIdxList{mxidx}) = true;
clf; imshow(smallblob)
clf; imshow(largeblob)
If you want a close-cropped image of the blob itself, you can use the "image" property from regionprops()

태그

Community Treasure Hunt

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

Start Hunting!

Translated by