필터 지우기
필터 지우기

How can I show the objects found in segmentation?

조회 수: 7 (최근 30일)
Annie
Annie 2017년 3월 23일
댓글: Image Analyst 2017년 3월 25일
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