Trying to derive a 2D transformation matrix using only the images

和自甴很熟 提交于 2019-12-04 17:29:36

Not sure if you want manual or automatic...

Manual

If you specify the transformed coordinates of the four corners of your rectangle, then you can derive the transformation equations:

alt text http://www.praeclarum.org/so/wellner.png

(From Pierre Wellner's Interacting with Paper on the DigitalDesk and more details in his Thesis)

Now you just have to solve for the coefficients of the equation.

With four point pairs, the two sets of four simultaneous linear equations can be quickly solved by Gaussian Elimination to find the values of c1-8.

Lastly, you can turn those equations into the 3x3 matrices you want. The above equations are powerful enough to do non-linear transformations and you can simplify it into the 3x3 affine shear matrix.

But I would just stick with the nonliner equations (above) since they can handle perspective distortion.

Automatic

Same method, but you can use an edge-detector comboined with a line detection algorithm to find a set of 4-ish lines that makeup a rectangle.

If your image rectangles really stand out (whiteish images on a dark background), then you can use corner detection available from libraries like OpenCV's Feature Detection (see cvCornerHarris).

You can intersect those lines to find the four corners and use the transformation equation.

You only need 3 points to define a 3x3 transformation matrix. If you have the points (0,0), (0,1) and (1,0) and transform them by the matrix [a b c d e f 0 0 1], you'll get (c,f), (b,e) and (a,d).

I think you should start by providing a list of, say 6 3 points (for 6 unknowns) with X/Y coordinates before and after transformation.

Then somebody more clever than I should pop that into a set of linear equations and then feed it to (say) Wolfram Alpha for solving.

The top of Java's documentation for AffineTransform shows how the matrix needs to be set up:

[ x']   [  m00  m01  m02  ] [ x ]   [ m00x + m01y + m02 ]
[ y'] = [  m10  m11  m12  ] [ y ] = [ m10x + m11y + m12 ]
[ 1 ]   [   0    0    1   ] [ 1 ]   [         1         ]

Removing most of the fluff leaves:

[ x']   [ m00x + m01y + m02 ]
[ y'] = [ m10x + m11y + m12 ]

Then you just set up a set of 6 x 2 equations like this:

m00x + m01y + m02 - x' = 0
m10x + m11y + m12 - y' = 0

(repeat for 2 other x/y before/after pairs)

and throw them at an equation solver.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!