Leptonica 1.68
C Image Processing Library

affinecompose.c File Reference

Composable affine coordinate transforms. More...

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

l_float32createMatrix2dTranslate (l_float32 transx, l_float32 transy)
l_float32createMatrix2dScale (l_float32 scalex, l_float32 scaley)
l_float32createMatrix2dRotate (l_float32 xc, l_float32 yc, l_float32 angle)
PTAptaTranslate (PTA *ptas, l_float32 transx, l_float32 transy)
PTAptaScale (PTA *ptas, l_float32 scalex, l_float32 scaley)
PTAptaRotate (PTA *ptas, l_float32 xc, l_float32 yc, l_float32 angle)
BOXAboxaTranslate (BOXA *boxas, l_float32 transx, l_float32 transy)
BOXAboxaScale (BOXA *boxas, l_float32 scalex, l_float32 scaley)
BOXAboxaRotate (BOXA *boxas, l_float32 xc, l_float32 yc, l_float32 angle)
PTAptaAffineTransform (PTA *ptas, l_float32 *mat)
BOXAboxaAffineTransform (BOXA *boxas, l_float32 *mat)
l_int32 l_productMatVec (l_float32 *mat, l_float32 *vecs, l_float32 *vecd, l_int32 size)
l_int32 l_productMat2 (l_float32 *mat1, l_float32 *mat2, l_float32 *matd, l_int32 size)
l_int32 l_productMat3 (l_float32 *mat1, l_float32 *mat2, l_float32 *mat3, l_float32 *matd, l_int32 size)
l_int32 l_productMat4 (l_float32 *mat1, l_float32 *mat2, l_float32 *mat3, l_float32 *mat4, l_float32 *matd, l_int32 size)

Detailed Description

Composable affine coordinate transforms.

    Composable coordinate transforms
         l_float32   *createMatrix2dTranslate()
         l_float32   *createMatrixScale()
         l_float32   *createMatrixRotate()

    Special coordinate transforms on pta
         PTA         *ptaTranslate()
         PTA         *ptaScale()
         PTA         *ptaRotate()

    Special coordinate transforms on boxa
         BOXA        *boxaTranslate()
         BOXA        *boxaScale()
         BOXA        *boxaRotate()

    General coordinate transform on pta and boxa
         PTA         *ptaAffineTransform()
         BOXA        *boxaAffineTransform()

    Matrix operations
         l_int32      l_productMatVec()
         l_int32      l_productMat2()
         l_int32      l_productMat3()
         l_int32      l_productMat4()

Definition in file affinecompose.c.


Function Documentation

l_float32* createMatrix2dTranslate ( l_float32  transx,
l_float32  transy 
)

createMatrix2dTranslate()

Input: transx (x component of translation wrt. the origin) transy (y component of translation wrt. the origin) Return: 3x3 transform matrix, or null on error

Notes; (1) The translation is equivalent to: v' = Av where v and v' are 1x3 column vectors in the form v = [x, y, 1]^ (^ denotes transpose) and the affine tranlation matrix is A = [ 1 0 tx 0 1 ty 0 0 1 ]

(2) We consider translation as with respect to a fixed origin. In a clipping operation, the origin moves and the points are fixed, and you use (-tx, -ty) where (tx, ty) is the translation vector of the origin.

Definition at line 77 of file affinecompose.c.

References CALLOC, ERROR_PTR, NULL, and PROCNAME.

Referenced by main().

l_float32* createMatrix2dScale ( l_float32  scalex,
l_float32  scaley 
)

createMatrix2dScale()

Input: scalex (horizontal scale factor) scaley (vertical scale factor) Return: 3x3 transform matrix, or null on error

Notes; (1) The scaling is equivalent to: v' = Av where v and v' are 1x3 column vectors in the form v = [x, y, 1]^ (^ denotes transpose) and the affine scaling matrix is A = [ sx 0 0 0 sy 0 0 0 1 ]

(2) We consider scaling as with respect to a fixed origin. In other words, the origin is the only point that doesn't move in the scaling transform.

Definition at line 116 of file affinecompose.c.

References CALLOC, ERROR_PTR, NULL, and PROCNAME.

Referenced by main().

l_float32* createMatrix2dRotate ( l_float32  xc,
l_float32  yc,
l_float32  angle 
)

createMatrix2dRotate()

Input: xc, yc (location of center of rotation) angle (rotation in radians; clockwise is positive) Return: 3x3 transform matrix, or null on error

Notes; (1) The rotation is equivalent to: v' = Av where v and v' are 1x3 column vectors in the form v = [x, y, 1]^ (^ denotes transpose) and the affine rotation matrix is A = [ cosa -sina xc*(1-cosa) + yc*sina sina cosa yc*(1-cosa) - xc*sina 0 0 1 ]

If the rotation is about the origin, (xc, yc) = (0, 0) and this simplifies to A = [ cosa -sina 0 sina cosa 0 0 0 1 ]

These relations follow from the following equations, which you can convince yourself are correct as follows. Draw a circle centered on (xc,yc) and passing through (x,y), with (x',y') on the arc at an angle 'a' clockwise from (x,y). [ Hint: cos(a + b) = cosa * cosb - sina * sinb sin(a + b) = sina * cosb + cosa * sinb ]

x' - xc = (x - xc) * cosa - (y - yc) * sina y' - yc = (x - xc) * sina + (y - yc) * cosa

Definition at line 167 of file affinecompose.c.

References CALLOC, ERROR_PTR, NULL, and PROCNAME.

Referenced by main().

PTA* ptaTranslate ( PTA ptas,
l_float32  transx,
l_float32  transy 
)

ptaTranslate()

Input: ptas (for initial points) transx (x component of translation wrt. the origin) transy (y component of translation wrt. the origin) Return: ptad (translated points), or null on error

Notes; (1) See createMatrix2dTranslate() for details of transform.

Definition at line 207 of file affinecompose.c.

References ERROR_PTR, NULL, PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), ptaGetPt(), HeapElement::x, and HeapElement::y.

Referenced by boxaTranslate().

PTA* ptaScale ( PTA ptas,
l_float32  scalex,
l_float32  scaley 
)

ptaScale()

Input: ptas (for initial points) scalex (horizontal scale factor) scaley (vertical scale factor) Return: 0 if OK; 1 on error

Notes; (1) See createMatrix2dScale() for details of transform.

Definition at line 244 of file affinecompose.c.

References ERROR_PTR, NULL, PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), ptaGetPt(), HeapElement::x, and HeapElement::y.

Referenced by boxaScale().

PTA* ptaRotate ( PTA ptas,
l_float32  xc,
l_float32  yc,
l_float32  angle 
)

ptaRotate()

Input: ptas (for initial points) (xc, yc) (location of center of rotation) angle (rotation in radians; clockwise is positive) (&ptad) (<return> new locations) Return: 0 if OK; 1 on error

Notes; (1) See createMatrix2dScale() for details of transform.

Definition at line 282 of file affinecompose.c.

References ERROR_PTR, NULL, PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), ptaGetPt(), HeapElement::x, and HeapElement::y.

Referenced by boxaRotate().

BOXA* boxaTranslate ( BOXA boxas,
l_float32  transx,
l_float32  transy 
)

boxaTranslate()

Input: boxas transx (x component of translation wrt. the origin) transy (y component of translation wrt. the origin) Return: boxad (translated boxas), or null on error

Notes; (1) See createMatrix2dTranslate() for details of transform.

Definition at line 327 of file affinecompose.c.

References boxaConvertToPta(), ERROR_PTR, NULL, PROCNAME, ptaConvertToBoxa(), ptaDestroy(), and ptaTranslate().

Referenced by main().

BOXA* boxaScale ( BOXA boxas,
l_float32  scalex,
l_float32  scaley 
)

boxaScale()

Input: boxas scalex (horizontal scale factor) scaley (vertical scale factor) Return: boxad (scaled boxas), or null on error

Notes; (1) See createMatrix2dScale() for details of transform.

Definition at line 360 of file affinecompose.c.

References boxaConvertToPta(), ERROR_PTR, NULL, PROCNAME, ptaConvertToBoxa(), ptaDestroy(), and ptaScale().

Referenced by main().

BOXA* boxaRotate ( BOXA boxas,
l_float32  xc,
l_float32  yc,
l_float32  angle 
)

boxaRotate()

Input: boxas (xc, yc) (location of center of rotation) angle (rotation in radians; clockwise is positive) Return: boxad (scaled boxas), or null on error

Notes; (1) See createMatrix2dRotate() for details of transform.

Definition at line 393 of file affinecompose.c.

References boxaConvertToPta(), ERROR_PTR, NULL, PROCNAME, ptaConvertToBoxa(), ptaDestroy(), and ptaRotate().

Referenced by main().

PTA* ptaAffineTransform ( PTA ptas,
l_float32 mat 
)

ptaAffineTransform()

Input: ptas (for initial points) mat (3x3 transform matrix; canonical form) Return: ptad (transformed points), or null on error

Definition at line 426 of file affinecompose.c.

References ERROR_PTR, l_productMatVec(), NULL, PROCNAME, ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetPt().

Referenced by boxaAffineTransform().

BOXA* boxaAffineTransform ( BOXA boxas,
l_float32 mat 
)

boxaAffineTransform()

Input: boxas mat (3x3 transform matrix; canonical form) Return: boxad (transformed boxas), or null on error

Definition at line 462 of file affinecompose.c.

References boxaConvertToPta(), ERROR_PTR, NULL, PROCNAME, ptaAffineTransform(), ptaConvertToBoxa(), and ptaDestroy().

Referenced by main().

l_int32 l_productMatVec ( l_float32 mat,
l_float32 vecs,
l_float32 vecd,
l_int32  size 
)

l_productMatVec()

Input: mat (square matrix, as a 1-dimensional ^2 array) vecs (input column vector of length ) vecd (result column vector) size (matrix is x ; vectors are length ) Return: 0 if OK, 1 on error

Definition at line 497 of file affinecompose.c.

References ERROR_INT, PROCNAME, and size.

Referenced by ptaAffineTransform().

l_int32 l_productMat2 ( l_float32 mat1,
l_float32 mat2,
l_float32 matd,
l_int32  size 
)

l_productMat2()

Input: mat1 (square matrix, as a 1-dimensional size^2 array) mat2 (square matrix, as a 1-dimensional size^2 array) matd (square matrix; product stored here) size (of matrices) Return: 0 if OK, 1 on error

Definition at line 533 of file affinecompose.c.

References ERROR_INT, PROCNAME, and size.

Referenced by l_productMat3(), and l_productMat4().

l_int32 l_productMat3 ( l_float32 mat1,
l_float32 mat2,
l_float32 mat3,
l_float32 matd,
l_int32  size 
)

l_productMat3()

Input: mat1 (square matrix, as a 1-dimensional size^2 array) mat2 (square matrix, as a 1-dimensional size^2 array) mat3 (square matrix, as a 1-dimensional size^2 array) matd (square matrix; product stored here) size (of matrices) Return: 0 if OK, 1 on error

Definition at line 572 of file affinecompose.c.

References CALLOC, ERROR_INT, FREE, l_productMat2(), NULL, and PROCNAME.

Referenced by l_productMat4(), and main().

l_int32 l_productMat4 ( l_float32 mat1,
l_float32 mat2,
l_float32 mat3,
l_float32 mat4,
l_float32 matd,
l_int32  size 
)

l_productMat4()

Input: mat1 (square matrix, as a 1-dimensional size^2 array) mat2 (square matrix, as a 1-dimensional size^2 array) mat3 (square matrix, as a 1-dimensional size^2 array) mat4 (square matrix, as a 1-dimensional size^2 array) matd (square matrix; product stored here) size (of matrices) Return: 0 if OK, 1 on error

Definition at line 612 of file affinecompose.c.

References CALLOC, ERROR_INT, FREE, l_productMat2(), l_productMat3(), NULL, and PROCNAME.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines