Ask Your Question
1

Gap Filling Contours / Lines

asked 2015-01-21 11:46:51 -0600

AlexRothberg gravatar image

updated 2015-10-05 14:17:29 -0600

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.

edit retag flag offensive close merge delete

Comments

1

Try a 5x5 or 7x7 kernel

Pedro Batista gravatar imagePedro Batista ( 2015-01-22 06:10:25 -0600 )edit

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

AlexRothberg gravatar imageAlexRothberg ( 2015-01-22 08:37:37 -0600 )edit

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

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-23 08:24:45 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
4

answered 2015-01-22 08:36:18 -0600

essamzaky gravatar image

updated 2015-10-05 14:14:25 -0600

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

edit flag offensive delete link more
1

answered 2015-01-21 21:31:42 -0600

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.

edit flag offensive delete link more

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

Blackwaveblackaxis gravatar imageBlackwaveblackaxis ( 2017-07-20 08:26:37 -0600 )edit
1

answered 2015-01-24 01:49:01 -0600

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...

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2015-01-21 11:46:51 -0600

Seen: 13,424 times

Last updated: Oct 05 '15