finding closed shapes in a binary edge image
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have an edge image, containing a picture I took withmy webcam.
I need to find which of the pixels are part of a closed shape, and DELETE the others. for that I want to write a function that returns a logical. saying YES or NO.
I know that the shapes that I want to detect are seperated at least one pixel from other unclosed shapes, and noise.
My solution for the problem was to scan the image until i find a white pixel. when I find it, I will find its white neighbors, and follow one of them.
for example: the following matrix is a part of my image. pixels 1,5,9 are white 1 2 3 4 5 6 7 8 9
if Ill hit 5, I would find pixels no' 1 and 9 then I will go after the one I found first, and do that until I find a dead end(only black neighbor pixels), or I find that the pixel I got to has my starting point as a neighbor.
to avoid going back to the pixel I came from the previous iteration, I blacken it before ending the loop and going to the found neighbor.
An example for a problem is when I have white pixels in places 1,5,7,8,9:
1 5 789
like a vertex of a triangle
the algorithem can make a mistake by going from 5 to 8, then to 9, and determine that it is a dead end, when the truth is that it was an important shape.
I have a raw code. I'd be happy for some help:)
% finding closed shapes in binary picture function [w]=findclosed(pic,splacea) % w is a LOGICAL
[prow, pcul]=size(pic); flg=0; [rp,cp]=splace for rp=1:prow for cp=1:pcul if pic(rp,cp)==1 %TRUE = we ran into an edge %flg=1; first=[rp,cp]; mat=zeros(size(pic)) while flg==1 for neighr=0:2 %finding neighbors in distance of 1 for neighc=0:2 place=[rp,cp]; flg2=0; if (place~=[1,1])%the middle pixel
if ((place-[1,1]+[neighr,neighc])=1 && flg2~=1) %we found a white neighbor and it is the first
% mat(place-[1,1]+[neighr,neighc])=1;
pic(place-[1,1]+[neighr,neighc])=0;
[rp,cp]=place-[1,1]+[neighr,neighc];
flg2=1; %flg2 is a sign that we found one neighbor.
end
end
flg2=0;
end
end
end
end
end
end
thanks for the help Matar Maoz
0 comentarios
Respuestas (1)
Walter Roberson
el 28 de Feb. de 2011
Looks to me like you could imlabel() the image and then regionprops() and look for regions where the EulerNumber is 0.
Whether this works or not would depend upon what you are looking for. For example, should a figure 8 be found? How about something like a Q, a closed area that has spurs? How about something like the circles image as show on the imclose documentation? Or even the basic question of whether a solid area should be found or only areas that are outlines around an empty space?
0 comentarios
Ver también
Categorías
Más información sobre Get Started with Image Processing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!