Accusoft.FormFixSdk Namespace > RegistrationResult Class : GetAffineTransformation Method |
'Declaration Public Function GetAffineTransformation() As Matrix
'Usage Dim instance As RegistrationResult Dim value As Matrix value = instance.GetAffineTransformation()
public Matrix GetAffineTransformation()
public: Matrix* GetAffineTransformation();
public: Matrix^ GetAffineTransformation();
The returned transformation matrix represents the transformation from the coordinate system of the unaligned image into the coordinate system of the model (template) image. The origin of each of the coordinate systems is the top left corner of the image.
Inverting the TransformationTo get a matrix representing the mapping from the coordinate system of the model image to the coordinate system of the filled image, you must compute the inverse of the transformation matrix. To compute the inverse of this transformation, use the System.Drawing.Drawing2D.Matrix.Inverse() method. This will modify the transformation matrix so that it represents the transformation from the coordinate system of the template image to the coordinate system of the unaligned image.
Using the Transformation to Compute Field Locations in the Filled ImageTo compute the location of a field (as defined by a set of four points) in the unaligned image, first compute the inverse of the affine transformation matrix. Then use the System.Drawing.Drawing2D.Matrix.TransformPoints(Point[] points) method to apply the transform to an array of points.
// generate the affine transformation System.Drawing.Drawing2D.Matrix affineTransform = myRegistrationResult.GetAffineTransformation(); // invert the transformation so that it represents the // mapping from the template image to the filled image affineTransform.Invert(); // define a field within the template image System.Drawing.Rectangle myField = new System.Drawing.Rectangle(10, 10, 200, 50); // Get points that represent the corners of the field System.Drawing.Point topLeft, topRight, bottomLeft, bottomRight; topLeft = new System.Drawing.Point(myField.Left, myField.Top); topRight = new System.Drawing.Point(myField.Right, myField.Top); bottomLeft = new System.Drawing.Point(myField.Left, myField.Bottom); bottomRight = new System.Drawing.Point(myField.Right, myField.Bottom); // create array of the points System.Drawing.Point[] cornersOfField = new System.Drawing.Point[] { topLeft, topRight, bottomLeft, bottomRight }; // map the points into the filled image affineTransform.TransformPoints(cornersOfField); // use the transformed points int newXTopLeft = cornersOfField[0].X; int newYTopLeft = cornersOfField[0].Y;