Файл src/projective.c

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

Функции

PIXpixProjectiveSampledPta (PIX *pixs, PTA *ptad, PTA *ptas, l_int32 incolor)
PIXpixProjectiveSampled (PIX *pixs, l_float32 *vc, l_int32 incolor)
PIXpixProjectivePta (PIX *pixs, PTA *ptad, PTA *ptas, l_int32 incolor)
PIXpixProjective (PIX *pixs, l_float32 *vc, l_int32 incolor)
PIXpixProjectivePtaColor (PIX *pixs, PTA *ptad, PTA *ptas, l_uint32 colorval)
PIXpixProjectiveColor (PIX *pixs, l_float32 *vc, l_uint32 colorval)
PIXpixProjectivePtaGray (PIX *pixs, PTA *ptad, PTA *ptas, l_uint8 grayval)
PIXpixProjectiveGray (PIX *pixs, l_float32 *vc, l_uint8 grayval)
l_int32 getProjectiveXformCoeffs (PTA *ptas, PTA *ptad, l_float32 **pvc)
l_int32 projectiveXformSampledPt (l_float32 *vc, l_int32 x, l_int32 y, l_int32 *pxp, l_int32 *pyp)
l_int32 projectiveXformPt (l_float32 *vc, l_int32 x, l_int32 y, l_float32 *pxp, l_float32 *pyp)

Функции

l_int32 getProjectiveXformCoeffs ( PTA ptas,
PTA ptad,
l_float32 **  pvc 
)

getProjectiveXformCoeffs()

Input: ptas (source 4 points; unprimed) ptad (transformed 4 points; primed) &vc (<return> vector of coefficients of transform) Return: 0 if OK; 1 on error

We have a set of 8 equations, describing the projective transformation that takes 4 points (ptas) into 4 other points (ptad). These equations are:

x1' = (c[0]*x1 + c[1]*y1 + c[2]) / (c[6]*x1 + c[7]*y1 + 1) y1' = (c[3]*x1 + c[4]*y1 + c[5]) / (c[6]*x1 + c[7]*y1 + 1) x2' = (c[0]*x2 + c[1]*y2 + c[2]) / (c[6]*x2 + c[7]*y2 + 1) y2' = (c[3]*x2 + c[4]*y2 + c[5]) / (c[6]*x2 + c[7]*y2 + 1) x3' = (c[0]*x3 + c[1]*y3 + c[2]) / (c[6]*x3 + c[7]*y3 + 1) y3' = (c[3]*x3 + c[4]*y3 + c[5]) / (c[6]*x3 + c[7]*y3 + 1) x4' = (c[0]*x4 + c[1]*y4 + c[2]) / (c[6]*x4 + c[7]*y4 + 1) y4' = (c[3]*x4 + c[4]*y4 + c[5]) / (c[6]*x4 + c[7]*y4 + 1)

Multiplying both sides of each eqn by the denominator, we get

AC = B

where B and C are column vectors

B = [ x1' y1' x2' y2' x3' y3' x4' y4' ] C = [ c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] ]

and A is the 8x8 matrix

x1 y1 1 0 0 0 -x1*x1' -y1*x1' 0 0 0 x1 y1 1 -x1*y1' -y1*y1' x2 y2 1 0 0 0 -x2*x2' -y2*x2' 0 0 0 x2 y2 1 -x2*y2' -y2*y2' x3 y3 1 0 0 0 -x3*x3' -y3*x3' 0 0 0 x3 y3 1 -x3*y3' -y3*y3' x4 y4 1 0 0 0 -x4*x4' -y4*x4' 0 0 0 x4 y4 1 -x4*y4' -y4*y4'

These eight equations are solved here for the coefficients C.

These eight coefficients can then be used to find the mapping (x,y) --> (x',y'):

x' = (c[0]x + c[1]y + c[2]) / (c[6]x + c[7]y + 1) y' = (c[3]x + c[4]y + c[5]) / (c[6]x + c[7]y + 1)

that is implemented in projectiveXformSampled() and projectiveXFormInterpolated().

PIX* pixProjective ( PIX pixs,
l_float32 vc,
l_int32  incolor 
)

pixProjective()

Input: pixs (all depths; colormap ok) vc (vector of 8 coefficients for affine transformation) incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) Return: pixd, or null on error

Notes: (1) Brings in either black or white pixels from the boundary (2) Removes any existing colormap, if necessary, before transforming

PIX* pixProjectiveColor ( PIX pixs,
l_float32 vc,
l_uint32  colorval 
)

pixProjectiveColor()

Input: pixs (32 bpp) vc (vector of 6 coefficients for affine transformation) colorval (e.g., 0 to bring in BLACK, 0xffffff00 for WHITE) Return: pixd, or null on error

PIX* pixProjectiveGray ( PIX pixs,
l_float32 vc,
l_uint8  grayval 
)

pixProjectiveGray()

Input: pixs (8 bpp) vc (vector of 8 coefficients for affine transformation) grayval (0 to bring in BLACK, 255 for WHITE) Return: pixd, or null on error

PIX* pixProjectivePta ( PIX pixs,
PTA ptad,
PTA ptas,
l_int32  incolor 
)

pixProjectivePta()

Input: pixs (all depths; colormap ok) ptad (4 pts of final coordinate space) ptas (4 pts of initial coordinate space) incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) Return: pixd, or null on error

Notes: (1) Brings in either black or white pixels from the boundary (2) Removes any existing colormap, if necessary, before transforming

PIX* pixProjectivePtaColor ( PIX pixs,
PTA ptad,
PTA ptas,
l_uint32  colorval 
)

pixProjectivePtaColor()

Input: pixs (32 bpp) ptad (4 pts of final coordinate space) ptas (4 pts of initial coordinate space) colorval (e.g., 0 to bring in BLACK, 0xffffff00 for WHITE) Return: pixd, or null on error

PIX* pixProjectivePtaGray ( PIX pixs,
PTA ptad,
PTA ptas,
l_uint8  grayval 
)

pixProjectivePtaGray()

Input: pixs (8 bpp) ptad (4 pts of final coordinate space) ptas (4 pts of initial coordinate space) grayval (0 to bring in BLACK, 255 for WHITE) Return: pixd, or null on error

PIX* pixProjectiveSampled ( PIX pixs,
l_float32 vc,
l_int32  incolor 
)

pixProjectiveSampled()

Input: pixs (all depths) vc (vector of 8 coefficients for projective transformation) incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) Return: pixd, or null on error

Notes: (1) Brings in either black or white pixels from the boundary. (2) Retains colormap, which you can do for a sampled transform.. (3) For 8 or 32 bpp, much better quality is obtained by the somewhat slower pixProjective(). See that function for relative timings between sampled and interpolated.

PIX* pixProjectiveSampledPta ( PIX pixs,
PTA ptad,
PTA ptas,
l_int32  incolor 
)

pixProjectiveSampledPta()

Input: pixs (all depths) ptad (4 pts of final coordinate space) ptas (4 pts of initial coordinate space) incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) Return: pixd, or null on error

Notes: (1) Brings in either black or white pixels from the boundary. (2) Retains colormap, which you can do for a sampled transform.. (3) No 3 of the 4 points may be collinear. (4) For 8 and 32 bpp pix, better quality is obtained by the somewhat slower pixProjectivePta(). See that function for relative timings between sampled and interpolated.

l_int32 projectiveXformPt ( l_float32 vc,
l_int32  x,
l_int32  y,
l_float32 pxp,
l_float32 pyp 
)

projectiveXformPt()

Input: vc (vector of 8 coefficients) (x, y) (initial point) (&xp, &yp) (<return> transformed point) Return: 0 if OK; 1 on error

Notes: (1) This computes the floating point location of the transformed point. (2) It does not check ptrs for returned data!

l_int32 projectiveXformSampledPt ( l_float32 vc,
l_int32  x,
l_int32  y,
l_int32 pxp,
l_int32 pyp 
)

projectiveXformSampledPt()

Input: vc (vector of 8 coefficients) (x, y) (initial point) (&xp, &yp) (<return> transformed point) Return: 0 if OK; 1 on error

Notes: (1) This finds the nearest pixel coordinates of the transformed point. (2) It does not check ptrs for returned data!


Документация по Leptonica. Последние изменения: Fri Aug 7 20:31:38 2009. Создано системой  doxygen 1.5.9