Файл src/skew.c

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

Макросы

#define DEBUG_PRINT_SCORES   0
#define DEBUG_PRINT_SWEEP   0
#define DEBUG_PRINT_BINARY   0
#define DEBUG_PRINT_ORTH   0
#define DEBUG_THRESHOLD   0
#define DEBUG_PLOT_SCORES   0

Функции

PIXpixDeskew (PIX *pixs, l_int32 redsearch)
PIXpixFindSkewAndDeskew (PIX *pixs, l_int32 redsearch, l_float32 *pangle, l_float32 *pconf)
l_int32 pixFindSkew (PIX *pixs, l_float32 *pangle, l_float32 *pconf)
l_int32 pixFindSkewSweep (PIX *pixs, l_float32 *pangle, l_int32 reduction, l_float32 sweeprange, l_float32 sweepdelta)
l_int32 pixFindSkewSweepAndSearch (PIX *pixs, l_float32 *pangle, l_float32 *pconf, l_int32 redsweep, l_int32 redsearch, l_float32 sweeprange, l_float32 sweepdelta, l_float32 minbsdelta)
l_int32 pixFindSkewSweepAndSearchScore (PIX *pixs, l_float32 *pangle, l_float32 *pconf, l_float32 *pendscore, l_int32 redsweep, l_int32 redsearch, l_float32 sweepcenter, l_float32 sweeprange, l_float32 sweepdelta, l_float32 minbsdelta)
l_int32 pixFindSkewSweepAndSearchScorePivot (PIX *pixs, l_float32 *pangle, l_float32 *pconf, l_float32 *pendscore, l_int32 redsweep, l_int32 redsearch, l_float32 sweepcenter, l_float32 sweeprange, l_float32 sweepdelta, l_float32 minbsdelta, l_int32 pivot)
l_int32 pixFindSkewOrthogonalRange (PIX *pixs, l_float32 *pangle, l_float32 *pconf, l_int32 redsweep, l_int32 redsearch, l_float32 sweeprange, l_float32 sweepdelta, l_float32 minbsdelta, l_float32 confprior)
l_int32 pixFindDifferentialSquareSum (PIX *pixs, l_float32 *psum)
l_int32 pixFindNormalizedSquareSum (PIX *pixs, l_float32 *phratio, l_float32 *pvratio, l_float32 *pfract)

Переменные

static const l_float32 DEFAULT_SWEEP_RANGE = 5.
static const l_float32 DEFAULT_SWEEP_DELTA = 1.
static const l_float32 DEFAULT_MINBS_DELTA = 0.01
static const l_int32 DEFAULT_SWEEP_REDUCTION = 4
static const l_int32 DEFAULT_BS_REDUCTION = 2
static const l_float32 MIN_DESKEW_ANGLE = 0.1
static const l_float32 MIN_ALLOWED_CONFIDENCE = 3.0
static const l_int32 MIN_VALID_MAXSCORE = 10000
static const l_float32 MINSCORE_THRESHOLD_CONSTANT = 0.000002

Макросы

#define DEBUG_PLOT_SCORES   0

#define DEBUG_PRINT_BINARY   0

#define DEBUG_PRINT_ORTH   0

#define DEBUG_PRINT_SCORES   0

#define DEBUG_PRINT_SWEEP   0

#define DEBUG_THRESHOLD   0


Функции

PIX* pixDeskew ( PIX pixs,
l_int32  redsearch 
)

pixDeskew()

Input: pixs (1 bpp) redsearch (for binary search: reduction factor = 1, 2 or 4) Return: deskewed pix, or null on error

Notes: (1) This is the most simple high level interface, for 1 bpp input. (2) It first finds the skew angle. If the angle is large enough, it returns a deskewed image; otherwise, it returns a clone.

l_int32 pixFindDifferentialSquareSum ( PIX pixs,
l_float32 psum 
)

pixFindDifferentialSquareSum()

Input: pixs &sum (<return> result) Return: 0 if OK, 1 on error

Notes: (1) At the top and bottom, we skip:

  • at least one scanline
  • not more than 10% of the image height
  • not more than 5% of the image width

l_int32 pixFindNormalizedSquareSum ( PIX pixs,
l_float32 phratio,
l_float32 pvratio,
l_float32 pfract 
)

pixFindNormalizedSquareSum()

Input: pixs &hratio (<optional return>=""> ratio of normalized horiz square sum to result if the pixel distribution were uniform) &vratio (<optional return>=""> ratio of normalized vert square sum to result if the pixel distribution were uniform) &fract (<optional return>=""> ratio of fg pixels to total pixels) Return: 0 if OK, 1 on error or if there are no fg pixels

Notes: (1) Let the image have h scanlines and N fg pixels. If the pixels were uniformly distributed on scanlines, the sum of squares of fg pixels on each scanline would be h * (N / h)^2. However, if the pixels are not uniformly distributed (e.g., for text), the sum of squares of fg pixels will be larger. We return in hratio and vratio the ratio of these two values. (2) If there are no fg pixels, hratio and vratio are returned as 0.0.

l_int32 pixFindSkew ( PIX pixs,
l_float32 pangle,
l_float32 pconf 
)

pixFindSkew()

Input: pixs (1 bpp) &angle (<return> angle required to deskew, in degrees) &conf (<return> confidence value is ratio max/min scores) Return: 0 if OK, 1 on error or if angle measurment not valid

Notes: (1) This is a simple high-level interface, that uses default values of the parameters for reasonable speed and accuracy. (2) The angle returned is the negative of the skew angle of the image. It is the angle required for deskew. Clockwise rotations are positive angles.

PIX* pixFindSkewAndDeskew ( PIX pixs,
l_int32  redsearch,
l_float32 pangle,
l_float32 pconf 
)

pixFindSkewAndDeskew()

Input: pixs (1 bpp) redsearch (for binary search: reduction factor = 1, 2 or 4) &angle (<optional return>=""> angle required to deskew, in degrees) &conf (<optional return>=""> conf value is ratio max/min scores) Return: deskewed pix, or null on error

Notes: (1) This first finds the skew angle. If the angle is large enough, it returns a deskewed image; otherwise, it returns a clone. (2) Use NULL for &angle and/or &conf if you don't want those values returned.

l_int32 pixFindSkewOrthogonalRange ( PIX pixs,
l_float32 pangle,
l_float32 pconf,
l_int32  redsweep,
l_int32  redsearch,
l_float32  sweeprange,
l_float32  sweepdelta,
l_float32  minbsdelta,
l_float32  confprior 
)

l_int32 pixFindSkewSweep ( PIX pixs,
l_float32 pangle,
l_int32  reduction,
l_float32  sweeprange,
l_float32  sweepdelta 
)

pixFindSkewSweep()

Input: pixs (1 bpp) &angle (<return> angle required to deskew, in degrees) reduction (factor = 1, 2, 4 or 8) sweeprange (half the full range; assumed about 0; in degrees) sweepdelta (angle increment of sweep; in degrees) Return: 0 if OK, 1 on error or if angle measurment not valid

Notes: (1) This examines the 'score' for skew angles with equal intervals. (2) Caller must check the return value for validity of the result.

l_int32 pixFindSkewSweepAndSearch ( PIX pixs,
l_float32 pangle,
l_float32 pconf,
l_int32  redsweep,
l_int32  redsearch,
l_float32  sweeprange,
l_float32  sweepdelta,
l_float32  minbsdelta 
)

pixFindSkewSweepAndSearch()

Input: pixs (1 bpp) &angle (<return> angle required to deskew; in degrees) &conf (<return> confidence given by ratio of max/min score) redsweep (sweep reduction factor = 1, 2, 4 or 8) redsearch (binary search reduction factor = 1, 2, 4 or 8; and must not exceed redsweep) sweeprange (half the full range, assumed about 0; in degrees) sweepdelta (angle increment of sweep; in degrees) minbsdelta (min binary search increment angle; in degrees) Return: 0 if OK, 1 on error or if angle measurment not valid

Notes: (1) This finds the skew angle, doing first a sweep through a set of equal angles, and then doing a binary search until convergence. (2) Caller must check the return value for validity of the result. (3) In computing the differential line sum variance score, we sum the result over scanlines, but we always skip:

l_int32 pixFindSkewSweepAndSearchScore ( PIX pixs,
l_float32 pangle,
l_float32 pconf,
l_float32 pendscore,
l_int32  redsweep,
l_int32  redsearch,
l_float32  sweepcenter,
l_float32  sweeprange,
l_float32  sweepdelta,
l_float32  minbsdelta 
)

pixFindSkewSweepAndSearchScore()

Input: pixs (1 bpp) &angle (<return> angle required to deskew; in degrees) &conf (<return> confidence given by ratio of max/min score) &endscore (<optional return>=""> max score; use NULL to ignore) redsweep (sweep reduction factor = 1, 2, 4 or 8) redsearch (binary search reduction factor = 1, 2, 4 or 8; and must not exceed redsweep) sweepcenter (angle about which sweep is performed; in degrees) sweeprange (half the full range, taken about sweepcenter; in degrees) sweepdelta (angle increment of sweep; in degrees) minbsdelta (min binary search increment angle; in degrees) Return: 0 if OK, 1 on error or if angle measurment not valid

Notes: (1) This finds the skew angle, doing first a sweep through a set of equal angles, and then doing a binary search until convergence. (2) There are two built-in constants that determine if the returned confidence is nonzero:

  • MIN_VALID_MAXSCORE (minimum allowed maxscore)
  • MINSCORE_THRESHOLD_CONSTANT (determines minimum allowed minscore, by multiplying by (height * width^2) If either of these conditions is not satisfied, the returned confidence value will be zero. The maxscore is optionally returned in this function to allow evaluation of the resulting angle by a method that is independent of the returned confidence value. (3) The larger the confidence value, the greater the probability that the proper alignment is given by the angle that maximizes variance. It should be compared to a threshold, which depends on the application. Values between 3.0 and 6.0 are common. (4) By default, the shear is about the UL corner.

l_int32 pixFindSkewSweepAndSearchScorePivot ( PIX pixs,
l_float32 pangle,
l_float32 pconf,
l_float32 pendscore,
l_int32  redsweep,
l_int32  redsearch,
l_float32  sweepcenter,
l_float32  sweeprange,
l_float32  sweepdelta,
l_float32  minbsdelta,
l_int32  pivot 
)

pixFindSkewSweepAndSearchScorePivot()

Input: pixs (1 bpp) &angle (<return> angle required to deskew; in degrees) &conf (<return> confidence given by ratio of max/min score) &endscore (<optional return>=""> max score; use NULL to ignore) redsweep (sweep reduction factor = 1, 2, 4 or 8) redsearch (binary search reduction factor = 1, 2, 4 or 8; and must not exceed redsweep) sweepcenter (angle about which sweep is performed; in degrees) sweeprange (half the full range, taken about sweepcenter; in degrees) sweepdelta (angle increment of sweep; in degrees) minbsdelta (min binary search increment angle; in degrees) pivot (L_SHEAR_ABOUT_CORNER, L_SHEAR_ABOUT_CENTER) Return: 0 if OK, 1 on error or if angle measurment not valid

Notes: (1) See notes in pixFindSkewSweepAndSearchScore(). (2) This allows choice of shear pivoting from either the UL corner or the center. For small angles, the ability to discriminate angles is better with shearing from the UL corner. However, for large angles (say, greater than 20 degrees), it is better to shear about the center because a shear from the UL corner loses too much of the image.


Переменные

const l_int32 DEFAULT_BS_REDUCTION = 2 [static]

const l_float32 DEFAULT_MINBS_DELTA = 0.01 [static]

const l_float32 DEFAULT_SWEEP_DELTA = 1. [static]

const l_float32 DEFAULT_SWEEP_RANGE = 5. [static]

const l_int32 DEFAULT_SWEEP_REDUCTION = 4 [static]

const l_float32 MIN_ALLOWED_CONFIDENCE = 3.0 [static]

const l_float32 MIN_DESKEW_ANGLE = 0.1 [static]

const l_int32 MIN_VALID_MAXSCORE = 10000 [static]

const l_float32 MINSCORE_THRESHOLD_CONSTANT = 0.000002 [static]


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