Home > Net >  How do I use Piecewise Affine Transformation to straighten curved text line/ contour?
How do I use Piecewise Affine Transformation to straighten curved text line/ contour?

Time:09-06

Consider the following image: enter image description here

and the following bounding contour( which is a smooth version of the output of a text-detection neural network of the above image ), so this contour is a given. enter image description here

I need to warp both images so that I end up with a straight enough textline, so that it can be fed to a text recognition neural network: enter image description here

using Piecewise Affine Transformation, or some other method. with an implementation if possible or key points of implementation in python.

I know how to find the medial axis, order its points, simplify it (e.g using Douglas-Peucker algorithm), and find the corresponding points on a straight line.

EDIT: the question can be rephrased -naively- as the following :
have you tried the "puppet warp" feature in Adobe Photoshop? you specify "joint" points on an image , and you move these points to the desired place to perform the image warping, we can calculate the source points using a simplified medial axis (e.g 20 points instead of 200 points), and calculate the corresponding target points on a straight line, how to perform Piecewise Affine Transformation using these two sets of points( source and target)?

EDIT: modified the images, my bad

Papers

Here's a paper that does the needed result: enter image description here

CodePudding user response:

Full code also available in enter image description here

2- find the corresponding points on a straight line, using the distance between each point and the next: enter image description here

3 - also added extra points on the ends, colored blue, so that the points fit the entire contour length enter image description here

4- create 2 copies of the source and target points, one copy translated up and the other translated down (I choose an offset of 50 here, but I guess the offset should equal the "stroke width" of the contour), so the source points are now like this: enter image description here

5- using the code enter image description here

  • Related