Morphological separation of two related borders

I have a question regarding the following scenario. As the image was processed, I got a path, which, unfortunately, is connected twice, as you can see in the bottom line. To make obvious what I want is just an exit line. So I zoomed in and highlighted the line, I want the image to be enlarged.

What I want from this choice is only part of the appearance that I have designated as green in the following figure. Sorry for my poor drawing skills .;)

I am using MatLab with IPT. So I also tried to figure out the bwmorph and hbreak , but he made a mistake.

How to solve this problem? If you were successful, could you tell me a little more about this? Thank you in advance!

Yours faithfully

+7
source share
2 answers

It seems your input image is slightly different from the one you posted, since I could not directly collect the branch points (there were too many of them). So, to begin processing your problem, I consider thinning, followed by detection of a branch point. I also expand them and remove them from the sparse image, this ensures that in fact there is no connection (4 or 8) between the different segments of the original image.

 f = im2bw(imread('http://i.imgur.com/yeFyF.png'), 0); g = bwmorph(f, 'thin', 'Inf'); h = g & ~bwmorph(bwmorph(g, 'branchpoints'), 'dilate'); 

Since h contains disconnected segments, the following operation collects the endpoints of all segments:

 u = bwmorph(h, 'endpoints'); 

Now, to solve your problem, I did a little analysis of what you want to drop. Consider two different segments, a and b , in h . We say that a and b overlap if the endpoints of the unit are contained in another. In terms of content, I simply mean if the starting point x of one is less than or equal to the other, and the ending x-point is greater than or equal to. In your case, the "mountain" overlaps with the segment that you want to delete. To identify each of them, you delete, consider their area. But, since these are segments, area is a meaningless term. To deal with this, I connected the endpoints of the segment and used just the internal points as the area. As you can clearly see, the area of ​​the overlapped segment below is very small, so we say that this is basically a line and discard it, preserving the "mountain" segment. To take this step, the u image is fundamental, because with it you clearly indicate where to start and stop tracing the outline. If you used image h as it is, you would have trouble figuring out where to start and stop picking contour points (that is, the raster order will give you the wrong indication of overlap).

To restore a segment as one (you currently have three of them), consider the points that you dropped from g to h , and use those that do not belong to the deleted lower segment.

+2
source

I would also use bwmorph

 %# find the branch point branchImg = bwmorph(img,'branchpoints'); %# grow the pixel to 3x3 branchImg = imdilate(branchImg,ones(3)); %# hide the branch point noBranchImg = img & ~branchImg; %# label the three lines lblImg = bwlabel(noBranchImg); %# in the original image, mask label #3 %# note that it may not always be #3 that you want to mask finalImg = img; finalImg(lblImg==3) = 0; %# show the result imshow(finalImg) 
+1
source

All Articles