Leptonica 1.54
|
#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 |
Input: pixs (any depth) redsearch (for binary search: reduction factor = 1, 2 or 4; use 0 for default) Return: pixd (deskewed pix), or null on error
Notes: (1) This binarizes if necessary and finds the skew angle. If the angle is large enough and there is sufficient confidence, it returns a deskewed image; otherwise, it returns a clone.
PIX* pixDeskewGeneral | ( | PIX * | pixs, |
l_int32 | redsweep, | ||
l_float32 | sweeprange, | ||
l_float32 | sweepdelta, | ||
l_int32 | redsearch, | ||
l_int32 | thresh, | ||
l_float32 * | pangle, | ||
l_float32 * | pconf | ||
) |
Input: pixs (any depth) redsweep (for linear search: reduction factor = 1, 2 or 4; use 0 for default) sweeprange (in degrees in each direction from 0; use 0.0 for default) sweepdelta (in degrees; use 0.0 for default) redsearch (for binary search: reduction factor = 1, 2 or 4; use 0 for default;) thresh (for binarizing the image; use 0 for default) &angle (<optional return>=""> angle required to deskew, in degrees; use NULL to skip) &conf (<optional return>=""> conf value is ratio of max/min scores; use NULL to skip) Return: pixd (deskewed pix), or null on error
Notes: (1) This binarizes if necessary and finds the skew angle. If the angle is large enough and there is sufficient confidence, it returns a deskewed image; otherwise, it returns a clone.
pixFindDifferentialSquareSum()
Input: pixs &sum (<return> result) Return: 0 if OK, 1 on error
Notes: (1) At the top and bottom, we skip:
l_int32 pixFindNormalizedSquareSum | ( | PIX * | pixs, |
l_float32 * | phratio, | ||
l_float32 * | pvratio, | ||
l_float32 * | pfract | ||
) |
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.
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.
Input: pixs (any depth) redsearch (for binary search: reduction factor = 1, 2 or 4; use 0 for default) &angle (<optional return>=""> angle required to deskew, in degrees; use NULL to skip) &conf (<optional return>=""> conf value is ratio of max/min scores; use NULL to skip) Return: pixd (deskewed pix), or null on error
Notes: (1) This binarizes if necessary and finds the skew angle. If the angle is large enough and there is sufficient confidence, it returns a deskewed image; otherwise, it returns a clone.
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 | ||
) |
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 | ||
) |
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:
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_BINARY_THRESHOLD = 130 [static] |
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 = 7. [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] |