Display each object in a binary image separately

2 visualizaciones (últimos 30 días)
Joaquim
Joaquim el 23 de Mzo. de 2017
Comentada: MashalS el 6 de Sept. de 2021
Hello everybody,
I have an image, with undefined number of objects, just like the image below.
I want to create an image for each one of the objects. For this case, I want to create 4 images each one with only one object. The new images should have the same size as the original image.
Is there anyone who could help me?
Cheers,
Joaquim
  3 comentarios
Joaquim
Joaquim el 23 de Mzo. de 2017
I used this instead
[L,num] = bwlabel(BW);
[sx,sy]=size(BW);
a=L;
element=zeros(sx,sy,num);
for i=1:num
a(L~=i)=0;
a(L==i)=1;
element(:,:,i)=a(:,:);
a=L;
end
I dont know how to use regionprops, although I know that it may use less memory.
Rik
Rik el 23 de Mzo. de 2017
As long as it gets the job done it usually doesn't matter how efficient your code is in terms of memory (in most of my cases anyway).

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 23 de Mzo. de 2017
Or, simply use ismember() to extract the blob you want. For example
[L, num] = bwlabel(BW);
for k = 1 : num
thisBlob = ismember(L, k);
figure
imshow(thisBlob, []);
end
  13 comentarios
Image Analyst
Image Analyst el 5 de Sept. de 2021
My code puts it in a loop over all blobs and shows you each blob one at a time because k varies in the loop. Your code only shows you one blob -- the k'th blob. But you need to specify k. Which one of the 4 do you want? See the attached demo to understand how the blobs are numbered/labeled.
MashalS
MashalS el 6 de Sept. de 2021
CODE :
L= bwlabel(BW);
thisBlob= ismember(L,1);
figure
imshow(thisBlob, []);
@Image Analyst,I understand how are blobs labelled. In the above code , I have displayed blob 1 on the figure. Using the similar syntax , Is it possible to use "ismember" to display more than one blob? for example: I have an image with 9 objects in it and i want to display only blob no.1 ,6 and 7 to be displayed in one figure.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by