Displaying objects found with bwconncomp

5 visualizaciones (últimos 30 días)
Ivan Aguilar
Ivan Aguilar el 11 de Oct. de 2021
Respondida: DGM el 11 de Oct. de 2021
I have found the amount of objects in my binary image, but I am not sure how to display those objects.
  2 comentarios
Walter Roberson
Walter Roberson el 11 de Oct. de 2021
If you have (for example) 73 connected components, do you want 73 figures, each of which shows the full-sized image but with everything black except for the connected component which is in its proper relative position ?
Ivan Aguilar
Ivan Aguilar el 11 de Oct. de 2021
Not all components, just two, the two that have the maximum and minimum areas.

Iniciar sesión para comentar.

Respuestas (1)

DGM
DGM el 11 de Oct. de 2021
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()

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by