How can I show the objects found in segmentation?

4 次查看(过去 30 天)
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.

采纳的回答

Gopichandh Danala
Gopichandh Danala 2017-3-23
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 个评论
Gopichandh Danala
Gopichandh Danala 2017-3-24
Here I am creating a tempImg for each object displaying it, repeating this process for all available objects in BW
Image Analyst
Image Analyst 2017-3-25
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.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2017-3-24
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

类别

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