Leptonica  1.83.1
Image processing and image analysis suite
affinecompose.c File Reference
#include <math.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

l_float32 * createMatrix2dTranslate (l_float32 transx, l_float32 transy)
 
l_float32 * createMatrix2dScale (l_float32 scalex, l_float32 scaley)
 
l_float32 * createMatrix2dRotate (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_ok l_productMatVec (l_float32 *mat, l_float32 *vecs, l_float32 *vecd, l_int32 size)
 
l_ok l_productMat2 (l_float32 *mat1, l_float32 *mat2, l_float32 *matd, l_int32 size)
 
l_ok l_productMat3 (l_float32 *mat1, l_float32 *mat2, l_float32 *mat3, l_float32 *matd, l_int32 size)
 
l_ok l_productMat4 (l_float32 *mat1, l_float32 *mat2, l_float32 *mat3, l_float32 *mat4, l_float32 *matd, l_int32 size)
 

Detailed Description


     Composable coordinate transforms
          l_float32   *createMatrix2dTranslate()
          l_float32   *createMatrix2dScale()
          l_float32   *createMatrix2dRotate()

     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

◆ boxaAffineTransform()

BOXA* boxaAffineTransform ( BOXA boxas,
l_float32 *  mat 
)

boxaAffineTransform()

Parameters
[in]boxas
[in]mat3x3 transform matrix; canonical form
Returns
boxad transformed boxas, or NULL on error

Definition at line 473 of file affinecompose.c.

References boxaConvertToPta(), ptaAffineTransform(), ptaConvertToBoxa(), and ptaDestroy().

◆ boxaRotate()

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

boxaRotate()

Parameters
[in]boxas
[in]xc,yclocation of center of rotation
[in]anglerotation in radians; clockwise is positive
Returns
boxad scaled boxas, or NULL on error

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

Definition at line 408 of file affinecompose.c.

References boxaConvertToPta(), ptaConvertToBoxa(), ptaDestroy(), and ptaRotate().

◆ boxaScale()

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

boxaScale()

Parameters
[in]boxas
[in]scalexhorizontal scale factor
[in]scaleyvertical scale factor
Returns
boxad scaled boxas, or NULL on error

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

Definition at line 377 of file affinecompose.c.

References boxaConvertToPta(), ptaConvertToBoxa(), ptaDestroy(), and ptaScale().

◆ boxaTranslate()

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

boxaTranslate()

Parameters
[in]boxas
[in]transxx component of translation wrt. the origin
[in]transyy component of translation wrt. the origin
Returns
boxad translated boxas, or NULL on error

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

Definition at line 346 of file affinecompose.c.

References boxaConvertToPta(), ptaConvertToBoxa(), ptaDestroy(), and ptaTranslate().

◆ createMatrix2dRotate()

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

createMatrix2dRotate()

Parameters
[in]xc,yclocation of center of rotation
[in]anglerotation in radians; clockwise is positive
Returns
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: cosa + b = cosa * cosb - sina * sinb
                  sina + b = sina * cosb + cosa * sinb ]

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

Definition at line 179 of file affinecompose.c.

◆ createMatrix2dScale()

l_float32* createMatrix2dScale ( l_float32  scalex,
l_float32  scaley 
)

createMatrix2dScale()

Parameters
[in]scalexhorizontal scale factor
[in]scaleyvertical scale factor
Returns
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 130 of file affinecompose.c.

◆ createMatrix2dTranslate()

l_float32* createMatrix2dTranslate ( l_float32  transx,
l_float32  transy 
)

createMatrix2dTranslate()

Parameters
[in]transxx component of translation wrt. the origin
[in]transyy component of translation wrt. the origin
Returns
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 translation 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 93 of file affinecompose.c.

◆ l_productMat2()

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

l_productMat2()

Parameters
[in]mat1square matrix, as a 1-dimensional size^2 array
[in]mat2square matrix, as a 1-dimensional size^2 array
[in]matdsquare matrix; product stored here
[in]sizeof matrices
Returns
0 if OK, 1 on error

Definition at line 540 of file affinecompose.c.

Referenced by l_productMat3(), and l_productMat4().

◆ l_productMat3()

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

l_productMat3()

Parameters
[in]mat1square matrix, as a 1-dimensional size^2 array
[in]mat2square matrix, as a 1-dimensional size^2 array
[in]mat3square matrix, as a 1-dimensional size^2 array
[in]matdsquare matrix; product stored here
[in]sizeof matrices
Returns
0 if OK, 1 on error

Definition at line 577 of file affinecompose.c.

References l_productMat2().

Referenced by l_productMat4().

◆ l_productMat4()

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

l_productMat4()

Parameters
[in]mat1square matrix, as a 1-dimensional size^2 array
[in]mat2square matrix, as a 1-dimensional size^2 array
[in]mat3square matrix, as a 1-dimensional size^2 array
[in]mat4square matrix, as a 1-dimensional size^2 array
[in]matdsquare matrix; product stored here
[in]sizeof matrices
Returns
0 if OK, 1 on error

Definition at line 616 of file affinecompose.c.

References l_productMat2(), and l_productMat3().

◆ l_productMatVec()

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

l_productMatVec()

Parameters
[in]matsquare matrix, as a 1-dimensional size^2 array
[in]vecsinput column vector of length size
[in]vecdresult column vector
[in]sizematrix is size x size; vectors are length size
Returns
0 if OK, 1 on error

Definition at line 506 of file affinecompose.c.

Referenced by ptaAffineTransform().

◆ ptaAffineTransform()

PTA* ptaAffineTransform ( PTA ptas,
l_float32 *  mat 
)

ptaAffineTransform()

Parameters
[in]ptasfor initial points
[in]mat3x3 transform matrix; canonical form
Returns
ptad transformed points, or NULL on error

Definition at line 439 of file affinecompose.c.

References l_productMatVec(), ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetPt().

Referenced by boxaAffineTransform().

◆ ptaRotate()

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

ptaRotate()

Parameters
[in]ptasfor initial points
[in]xc,yclocation of center of rotation
[in]anglerotation in radians; clockwise is positive
Returns
0 if OK; 1 on error
Notes;
     (1) See createMatrix2dScale() for details of transform.
     (2) This transform can be thought of as composed of the
         sum of two parts:
          a) an (x,y)-dependent rotation about the origin:
             xr = x * cosa - y * sina
             yr = x * sina + y * cosa
          b) an (x,y)-independent translation that depends on the
             rotation center and the angle:
             xt = xc - xc * cosa + yc * sina
             yt = yc - xc * sina - yc * cosa
         The translation part (xt,yt) is equal to the difference
         between the center (xc,yc) and the location of the
         center after it is rotated about the origin.

Definition at line 303 of file affinecompose.c.

References ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetPt().

Referenced by boxaRotate().

◆ ptaScale()

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

ptaScale()

Parameters
[in]ptasfor initial points
[in]scalexhorizontal scale factor
[in]scaleyvertical scale factor
Returns
0 if OK; 1 on error
Notes:
     (1) See createMatrix2dScale() for details of transform.

Definition at line 254 of file affinecompose.c.

References ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetPt().

Referenced by boxaScale().

◆ ptaTranslate()

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

ptaTranslate()

Parameters
[in]ptasfor initial points
[in]transxx component of translation wrt. the origin
[in]transyy component of translation wrt. the origin
Returns
ptad translated points, or NULL on error
Notes:
     (1) See createMatrix2dTranslate() for details of transform.

Definition at line 217 of file affinecompose.c.

References ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetPt().

Referenced by boxaTranslate().