-2

How can I programmatically dilate the contour of a given shape? Currently, I'm able to find and draw the contour of a shape using python+openCV, but I want to draw an offset to the contour of the shape in a raster image (like in the image below).

By offset, meaning expanding or minimizing the original shape, not just scaling it. The following is an example of that result: enter image description here

lorelayb
  • 33
  • 8
  • Do you want this from a raster image or from a vectorized representation ? And in what form should be the output ? –  Mar 04 '21 at 13:13
  • @YvesDaoust I'm using a raster image for both input and output. – lorelayb Mar 04 '21 at 14:44
  • Then dilate with a circular structuring element. Once to get the offset shape, and a second time to get its outline. –  Mar 04 '21 at 15:37

1 Answers1

1

Based on your sketch you don't seem to be interested in just scaling up the original contour. So I guess the simplest way to approach this is morphological region growing. With the help of dilation you can expand the region of your original contour in the image domain and then recover the newly created contour.

Have a look at this implementation

Scale contours up/grow outward

lwohlhart
  • 1,829
  • 12
  • 20