Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Morphological separation of two connected boundaries

I've got a question regarding the following scenario. As I post-process an image, I gained a contour, which is unfortunately twice connected as you can see at the bottom line. To make it obvious what I want is just the outter line. Therefore I zoomed in and marked the line, i want of the large image.

What I want from this selection is only the outter part, which I've marked as green in the next picture. Sorry for my bad drawing skills. ;)

I am using MatLab with the IPT. So I also tried to make out with bwmorph and the hbreak option, but it threw an error.

How do I solve that problem? If you were successful could you please tell me a bit more about it? Thank you in advance!

Sincerely

like image 641
mchlfchr Avatar asked Nov 27 '12 22:11

mchlfchr


People also ask

What are the two main operations of morphology?

The most basic morphological operations are dilation and erosion. Dilation adds pixels to the boundaries of objects in an image, while erosion removes pixels on object boundaries.

What are the five morphological operation?

Erosion, dilation, opening, closing: The four basic morphological operations together with some others can be implemented on a binary image via Process<Binary. However, these commands do not provide a user with a possibility to vary main parameters of the structuring element (SE) – size and shape.

What is morphological reconstruction?

Morphological reconstruction is based on morphological dilation, but has these distinguishing characteristics: Processing uses two images, a marker and a mask, rather than one image and a structuring element.

What is morphological smoothing?

Morphological Smoothing. • A basic morphological smoothing is an opening followed by a closing operation. – It removes both bright and dark artifacts of noise.


1 Answers

It seems your input image is a bit different than the one you posted, since I couldn't directly collect the branch points (there were too many of them). So, to start handling your problem I considering a thinning followed by branch point detection. I also dilate them and remove from the thinned image, this guarantees that in fact there is no connection (4 or 8) between the different segments in the initial 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 holds disconnected segments, the following operation collects the end points of all the segments:

u = bwmorph(h, 'endpoints');

Now to actually solve your problem I did some quick analysis on what you want to discard. Consider two distinct segments, a and b, in h. We say a and b overlap if the end points of one is contained in the other. By contained I simply mean if the starting x point of one is smaller or equal to the other, and the ending x point is greater or equal too. In your case, the "mountain" overlaps with the segment that you wish to remove. To determine each of them you remove, consider their area. But, since these are segments, area is a meaningless term. To handle that, I connected the end points of a segment, and used as area simply the interior points. As you can clearly notice, the area of the overlapped segment at bottom is very small, so we say it is basically a line and discard it while keeping the "mountain" segment. To do this step the image u is of fundamental importance, since with it you have a clear indication of where to start and stop tracking a contour. If you used the image has is , you would have trouble determining where to start and stop collecting the points of a contour (i.e., the raster order would give you incorrect overlapping indication).

To reconstruct the segment as a single one (currently you have three of them), consider the points you discarded from g in h, and use those that doesn't belong to the now removed bottom segment.

like image 118
mmgp Avatar answered Oct 20 '22 18:10

mmgp