Clear Filters
Clear Filters

How can I show the objects found in segmentation?

8 views (last 30 days)
Hello, everyone,
I'm working on a segmentation code but what I'm missing is to know how can I plot/show the segments of the image I have found in another figure, this is the code I have so far:
I=imread('Prueba1.png');
%Show original image;
figure
imagesc(I)
colormap('gray')
axis equal
title('Imagen Original')
I=double(rgb2gray(I));
figure
imagesc(I)
colormap('gray')
axis equal
title('Imagen Escala Grises')
IN=255-I;
f=bwlabel(IN,8);
figure
imagesc(f)
colormap('gray')
axis equal
g=regionprops(f,'Area','Centroid','Image');
[r,c]=size(g);
sprintf('Total of Objects: %d',r)
[r1,c1]=size(f);
figure
for o=1:r
%This is something I was trying but it just shows all of the figures:
imagesc(g(o,1).Image)
colormap('gray')
axis equal
drawnow
end
I think that I have to find where it starts and then draw it there, but I'm not quite sure about this, do you know anyway of doing this?
Thanks for your help.
P.S. This is the image I'm working on:
What I want to do is to have another image similar to the Gray Scale image here but that as the program is running I can see it's plotting. Thanks again.

Accepted Answer

Gopichandh Danala
Gopichandh Danala on 23 Mar 2017
In your code there is some noise when i saved the image, so I did multithresh it works anyway for segmentation of your image
Then I used label to segment each object seperately
Here is the sample code:
I=imread('IMO.jpg');
%Show original image;
figure
imshow(I,[])
title('Imagen Original')
I=double(rgb2gray(I));
figure
imshow(I,[])
title('Imagen Escala Grises')
% segmentation
levels = multithresh(I,1);
seg = imquantize(I, levels);
% figure, imshow(seg,[])
% remove background
seg2 = seg;
seg2(seg == 2) = 0;
% figure, imshow(seg2,[]);
% label image for each object
BW = bwlabel(seg2);
figure, imshow(BW,[]);
title('Labeled image');
% display or segment each object and display
for i = 1:max(BW(:))
tempImg = BW;
tempImg(BW ~= i) = 0;
figure, imshow(tempImg,[]);
title(strcat(num2str(i),'-th Object'));
end
If you have any doubts comment here.
Gopi
  3 Comments
Gopichandh Danala
Gopichandh Danala on 24 Mar 2017
Here I am creating a tempImg for each object displaying it, repeating this process for all available objects in BW
Image Analyst
Image Analyst on 25 Mar 2017
He's making a copy of the labeled image. Then he's setting all pixels that do not have a value in that copied image to zero, so that it will have only the one label left. You might prefer the ismember() method I used in my answer - that's what ismember() is built for.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 24 Mar 2017
Again....
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

Community Treasure Hunt

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

Start Hunting!