Search code examples
image-processinggraphics

Straightening a curved contour


Given a contour with an easily-identifiable edge, how would one straighten it and its contents, as pictured?

enter image description here


Solution

  • Detect the black edge and fit a spline curve to it.

    From that spline you will be able to draw normals, and mark points regularly along it. This forms a (u, v) mesh that is easy to straighten.

    To compute the destination image, draw horizontal rows, which correspond to particular normals in the source. Then sampling along the horizontal corresponds to some fractional (x, y) coordinates in the source. You can perform bilinear interpolation around the neighboring pixels to achieve good quality resampling.