Search code examples
pythonopencvbackground-subtraction

how to set equal intervals along boundaries of irregular shaped object in image in python?


I'm trying to set equal intervals along the boundary of a black and white image. Is there a way to do it?

I thought about first finding the edge of object using distance transform then scanning the image for the edge. I was thinking of starting with first pixel that is on the edge then find the pixel closest to it, eventually we'll get the list of edge pixels in order. But the runtime of that seems really slow.

Can someone help me with this?


Solution

  • You can probably use findCountours for that.

    Each individual contour is a Numpy array of (x,y) coordinates of boundary points of the object.

    So you have a list of points on your "boundary". Now you just need to fit consecutive points into a line and calculate which points you want on that line (I'll leave the math of that to you though :))