2

I have an image with free-form curved lines (actually lists of small line-segments) overlayed onto it, and I want to generate some kind of image-warp that will deform the image in such a way that these curves are deformed into horizontal straight lines.

I already have the coordinates of all the line-segment points stored separately so they don't have to be extracted from the image. What I'm looking for is an appropriate method of warping the image such that these lines are warped into straight ones.

thanks

kazimpal
  • 270
  • 3
  • 13
  • Free-form curved lines? This sounds difficult. Can you post an example image of the input and desired output? – Matt Montag Sep 26 '11 at 18:47
  • if you look at the two images at the top of this pagehttp://www.cs.cmu.edu/~ILIM/projects/IM/document_rectification/document_rectification.html – kazimpal Sep 27 '11 at 13:46
  • @user961255 So why it the method shown on the cmu website not good enough for your purpose? – Maurits Sep 27 '11 at 14:06
  • transforming each cell of the image independently using affine transformations creates discontinuities at the boundaries of the cells, hence my desire for a global transformation. – kazimpal Sep 30 '11 at 13:00

2 Answers2

1

You can use methods similar to those developed here: http://www-ui.is.s.u-tokyo.ac.jp/~takeo/research/rigid/

What you do, is you define an MxN grid of control points which covers your source image. You then need to determine how to modify each of your control points so that the final image will minimize some energy function (minimum curvature or something of this sort).

The final image is a linear warp determined by your control points (think of it as a 2D mesh whose texture is your source image and whose vertices' positions you're about to modify).

As long as your energy function can be expressed using linear equations, you can globally solve your problem (figuring out where to send each control point) using linear equations solver.

You express each of your source points (those which lie on your curved lines) using bi-linear interpolation weights of their surrounding grid points, then you express your restriction on the target by writing equations for these points.

After solving these linear equations you end up with destination grid points, then you just render your 2D mesh with the new vertices' positions.

ronb127
  • 51
  • 2
0

You need to start out with a mapping formula that given an output coordinate will provide the corresponding coordinate from the input image. Depending on the distortion you're trying to correct for, this can get exceedingly complex; your question doesn't specify the problem in enough detail. For example, are the curves at the top of the image the same as the curves on the bottom and the same as those in the middle? Do horizontal distances compress based on the angle of the line? Let's assume the simplest case where the horizontal coordinate doesn't need any correction at all, and the vertical simply needs a constant correction based on the horizontal. Here x,y are the coordinates on the input image, x',y' are the coordinates on the output image, and f() is the difference between the drawn line segment and your ideal straight line.

x = x'
y = y' + f(x')

Now you simply go through all the pixels of your output image, calculate the corresponding point in the input image, and copy the pixel. The wrinkle here is that your formula is likely to give you points that lie between input pixels, such as y=4.37. In that case you'll need to interpolate to get an intermediate value from the input; there are many interpolation methods for images and I won't try to get into that here. The simplest would be "nearest neighbor", where you simply round the coordinate to the nearest integer.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • ideally i'd want to do it in a as-rigid-as-possible sort of way. ways i've seen of doing this are to connect the curves with "vertical" curves to form a grid structure over the image and then warp each cell of the grid separately into a rectangle using an affine transformation. Such methods are ok but ideally i want to use the curves to generate some sort of global deformation like a grid-warp or a thin-plate-spline-esque warp instead of doing doing it patch-by-patch – kazimpal Sep 27 '11 at 13:45
  • if you look at the two images at the top of this page: http://www.cs.cmu.edu/~ILIM/projects/IM/document_rectification/document_rectification.html imagine curves drawn over each line of text in the first image. i want to use those curves to generate a warp that will produce the second image. these people use the grid + affine transformation method i just described, which isnt ideal for my purposes – kazimpal Sep 27 '11 at 13:49
  • @user961255, This falls into the "exceedingly complex" case that I spoke of. The x and y aren't independent, the curves are arbitrary in shape and vary across the image. The affine transform is one way of translating one set of coordinates to another, and in this case it might be the only practical option. – Mark Ransom Sep 27 '11 at 14:10