![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173868/image.png)
How can I segment an object with a hole in it from an image (bagel problem)?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
example: bagel.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153118/image.png)
%%Bagel image.
I have high resolution photographs of isolated objects. The final goal is to extract a) the full contour and b) a sort of filled-in mask of the object. This could be trivial, I'm new to image processing.
For an object without holes (book, pen, apple) this strategy has worked: apply activecontour with the image, a generous mask around it and many iterations. To get the outline, use edge with canny option afterward (other options also work fine).
But if the object has holes on the inside, these are filled (bagel, belt, ring). I will have to process really many of these images so anything that involves manual steps or describing starting-point shapes etc should be avoided. I also played with just using edge with various settings but I tend to get far too many edges within the object... Any ideas?
Thanks heaps!
Example
im=imread('bagel.png');
imshow(im);
im=imresize(im,0.3);
mask=zeros(size(im));
mask(25:end-25, 25:end-25)=1;
bw=activecontour(im,mask,1000);
figure, imshow(bw)
bw2=edge(bw,'canny',0.3)
0 commentaires
Réponse acceptée
Sean de Wolski
le 19 Nov 2013
Modifié(e) : Sean de Wolski
le 19 Nov 2013
I would just xor with the imfill(...,'hole') image:
I = imread('bagel.png');
BW = I>10;
BagelHole = xor(BW,imfill(BW,'holes'));
% View it
BW = double(BW);
BW(BagelHole) = 2;
imshow(label2rgb(BW));
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173868/image.png)
Plus de réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!