Ask Your Question
1

Gap Filling Contours / Lines

asked Jan 21 '15

AlexRothberg gravatar image

updated Oct 5 '15

I have the following image:

image description

and I would like to fill in its contours (i.e. I would like to gap fill the lines in this image).

I have tried a morphological closing, but using a rectangular kernel of size 3x3 with 10 iterations does not fill in the entire border.

Preview: (hide)

Comments

1

Try a 5x5 or 7x7 kernel

Pedro Batista gravatar imagePedro Batista (Jan 22 '15)edit

I tried an 11x11 rectangular kernel and that also did not work.

AlexRothberg gravatar imageAlexRothberg (Jan 22 '15)edit

I am sorry, but this is doesnt seem impossible with erosion and dilation. Can you explain why this doesnt work?

StevenPuttemans gravatar imageStevenPuttemans (Jan 23 '15)edit

3 answers

Sort by » oldest newest most voted
4

answered Jan 22 '15

essamzaky gravatar image

updated Oct 5 '15

Faster method use connected componnet and find contours

  1. Find all connected components by using find FindContour method
  2. Store contour for every Region(Connected componnet CC)
  3. calculate the Bounding Rect for every region (CC)
  4. Loop in all region
  5. For every region , find the nearest regions depending on the Bounding rect
  6. now you have the suspected regions which can be connected to region, compare the two contours and find the mimimum distance between the two contours , if the minimum distance is smaller than threshould (say 10 pixel) then now you can draw line from Point1 in first contour and point2 in second contour , Point1 and Point2 are the points which satisfy the minmum distance calculated before.
  7. repeat the proces for all regions

EDIT: you can find sample implemention code here

Preview: (hide)
1

answered Jan 22 '15

A simple solution could be to try a nearest neighbor approach, which may or may not work but will certainly be very slow. For every white pixel in the image find the nearest white pixels within a short distance range. If found, create a line between the two points. This could be speed up by skipping pixels;

An even simpler solution would be be to blur the image a few times, such that you would have a vague gray blur in the gap area. Then threshold the image such that anything not black becomes white.

Preview: (hide)

Comments

Could you please elaborate on your nearest neighbour approach? How would you go about creating the algorithm so it was only involving white pixels locating close by white pixels in a binary image, and once the nearesr white pixel was located, how would you ensure the algorithm drew a line between the 2 points

1

answered Jan 24 '15

I think, that an erosion and dilatation will do the job. And, as I see, you are using binary image, so you can just check if there is a white/black pixel in the window. BUT I'm not sure that will preserve the edges clear and sharp...

Preview: (hide)

Question Tools

2 followers

Stats

Asked: Jan 21 '15

Seen: 13,957 times

Last updated: Oct 05 '15