Leptonica  1.54
Файл src/dewarp1.c
#include <math.h>
#include "allheaders.h"

Функции

static l_int32 dewarpaExtendArraysToSize (L_DEWARPA *dewa, l_int32 size)
L_DEWARPdewarpCreate (PIX *pixs, l_int32 pageno)
L_DEWARPdewarpCreateRef (l_int32 pageno, l_int32 refpage)
void dewarpDestroy (L_DEWARP **pdew)
L_DEWARPAdewarpaCreate (l_int32 nptrs, l_int32 sampling, l_int32 redfactor, l_int32 minlines, l_int32 maxdist)
L_DEWARPAdewarpaCreateFromPixacomp (PIXAC *pixac, l_int32 useboth, l_int32 sampling, l_int32 minlines, l_int32 maxdist)
void dewarpaDestroy (L_DEWARPA **pdewa)
l_int32 dewarpaDestroyDewarp (L_DEWARPA *dewa, l_int32 pageno)
l_int32 dewarpaInsertDewarp (L_DEWARPA *dewa, L_DEWARP *dew)
L_DEWARPdewarpaGetDewarp (L_DEWARPA *dewa, l_int32 index)
l_int32 dewarpaSetCurvatures (L_DEWARPA *dewa, l_int32 max_linecurv, l_int32 min_diff_linecurv, l_int32 max_diff_linecurv, l_int32 max_edgecurv, l_int32 max_diff_edgecurv, l_int32 max_edgeslope)
l_int32 dewarpaUseBothArrays (L_DEWARPA *dewa, l_int32 useboth)
l_int32 dewarpaSetMaxDistance (L_DEWARPA *dewa, l_int32 maxdist)
L_DEWARPdewarpRead (const char *filename)
L_DEWARPdewarpReadStream (FILE *fp)
l_int32 dewarpWrite (const char *filename, L_DEWARP *dew)
l_int32 dewarpWriteStream (FILE *fp, L_DEWARP *dew)
L_DEWARPAdewarpaRead (const char *filename)
L_DEWARPAdewarpaReadStream (FILE *fp)
l_int32 dewarpaWrite (const char *filename, L_DEWARPA *dewa)
l_int32 dewarpaWriteStream (FILE *fp, L_DEWARPA *dewa)

Переменные

static const l_int32 INITIAL_PTR_ARRAYSIZE = 20
static const l_int32 MAX_PTR_ARRAYSIZE = 10000
static const l_int32 DEFAULT_ARRAY_SAMPLING = 30
static const l_int32 MIN_ARRAY_SAMPLING = 8
static const l_int32 DEFAULT_MIN_LINES = 15
static const l_int32 MIN_MIN_LINES = 4
static const l_int32 DEFAULT_MAX_REF_DIST = 16
static const l_int32 DEFAULT_MAX_LINECURV = 180
static const l_int32 DEFAULT_MIN_DIFF_LINECURV = 0
static const l_int32 DEFAULT_MAX_DIFF_LINECURV = 200
static const l_int32 DEFAULT_MAX_EDGECURV = 50
static const l_int32 DEFAULT_MAX_DIFF_EDGECURV = 40
static const l_int32 DEFAULT_MAX_EDGESLOPE = 80

Функции

L_DEWARPA* dewarpaCreate ( l_int32  nptrs,
l_int32  sampling,
l_int32  redfactor,
l_int32  minlines,
l_int32  maxdist 
)

dewarpaCreate()

Input: nptrs (number of dewarp page ptrs; typically the number of pages) sampling (use 0 for default value; the minimum allowed is 8) redfactor (of input images: 1 is full resolution; 2 is 2x reduced) minlines (minimum number of lines to accept; use 0 for default) maxdist (for locating reference disparity; use -1 for default) Return: dewa (or null on error)

Notes: (1) The sampling, minlines and maxdist parameters will be applied to all images. (2) The sampling factor is used for generating the disparity arrays from the input image. For 2x reduced input, use a sampling factor that is half the sampling you want on the full resolution images. (3) Use = 1 for full resolution; 2 for 2x reduction. All input images must be at one of these two resolutions. (4) is the minimum number of nearly full-length lines required to generate a vertical disparity array. The default number is 15. Use a smaller number to accept a questionable array, but not smaller than 4. (5) When a model can't be built for a page, it looks up to in either direction for a valid model with the same page parity. Use -1 for the default value of ; use 0 to avoid using a ref model. (6) The ptr array is expanded as necessary to accommodate page images.

L_DEWARPA* dewarpaCreateFromPixacomp ( PIXAC pixac,
l_int32  useboth,
l_int32  sampling,
l_int32  minlines,
l_int32  maxdist 
)

dewarpaCreateFromPixacomp()

Input: pixac (pixacomp of G4, 1 bpp images; with 1x1x1 placeholders) useboth (0 for vert disparity; 1 for both vert and horiz) sampling (use -1 or 0 for default value; otherwise minimum of 5) minlines (minimum number of lines to accept; e.g., 10) maxdist (for locating reference disparity; use -1 for default) Return: dewa (or null on error)

Notes: (1) The returned dewa has disparity arrays calculated and is ready for serialization or for use in dewarping. (2) The sampling, minlines and maxdist parameters are applied to all images. See notes in dewarpaCreate() for details. (3) The pixac is full. Placeholders, if any, are w=h=d=1 images, and the real input images are 1 bpp at full resolution. They are assumed to be cropped to the actual page regions, and may be arbitrarily sparse in the array. (4) The output dewarpa is indexed by the page number. The offset in the pixac gives the mapping between the array index in the pixac and the page number. (5) This adds the ref page models. (6) This can be used to make models for any desired set of pages. The direct models are only made for pages with images in the pixacomp; the ref models are made for pages of the same parity within of the nearest direct model.

void dewarpaDestroy ( L_DEWARPA **  pdewa)

dewarpaDestroy()

Input: &dewa (<will be="" set="" to="" null="" before="" returning>="">) Return: void

l_int32 dewarpaDestroyDewarp ( L_DEWARPA dewa,
l_int32  pageno 
)

dewarpaDestroyDewarp()

Input: dewa pageno (of dew to be destroyed) Return: 0 if OK, 1 on error

static l_int32 dewarpaExtendArraysToSize ( L_DEWARPA dewa,
l_int32  size 
) [static]

dewarpaExtendArraysToSize()

Input: dewa size (new size of dewarpa array) Return: 0 if OK; 1 on error

Notes: (1) If necessary, reallocs main and cache dewarpa ptr arrays to .

L_DEWARP* dewarpaGetDewarp ( L_DEWARPA dewa,
l_int32  index 
)

dewarpaGetDewarp()

Input: dewa (populated with dewarp structs for pages) index (into dewa: this is the pageno) Return: dew (handle; still owned by dewa), or null on error

l_int32 dewarpaInsertDewarp ( L_DEWARPA dewa,
L_DEWARP dew 
)

dewarpaInsertDewarp()

Input: dewarpa dewarp (to be added) Return: 0 if OK, 1 on error

Notes: (1) This inserts the dewarp into the array, which now owns it. It also keeps track of the largest page number stored. It must be done before the disparity model is built. (2) Note that this differs from the usual method of filling out arrays in leptonica, where the arrays are compact and new elements are typically added to the end. Here, the dewarp can be added anywhere, even beyond the initial allocation.

L_DEWARPA* dewarpaRead ( const char *  filename)

dewarpaRead()

Input: filename Return: dewa, or null on error

L_DEWARPA* dewarpaReadStream ( FILE *  fp)

dewarpaReadStream()

Input: stream Return: dewa, or null on error

Notes: (1) The serialized dewarp contains a Numa that gives the (increasing) page number of the dewarp structs that are contained. (2) Reference pages are added in after readback.

l_int32 dewarpaSetCurvatures ( L_DEWARPA dewa,
l_int32  max_linecurv,
l_int32  min_diff_linecurv,
l_int32  max_diff_linecurv,
l_int32  max_edgecurv,
l_int32  max_diff_edgecurv,
l_int32  max_edgeslope 
)

dewarpaSetCurvatures()

Input: dewa max_linecurv (-1 for default) min_diff_linecurv (-1 for default; 0 to accept all models) max_diff_linecurv (-1 for default) max_edgecurv (-1 for default) max_diff_edgecurv (-1 for default) max_edgeslope (-1 for default) Return: 0 if OK, 1 on error

Notes: (1) Approximating the line by a quadratic, the coefficent of the quadratic term is the curvature, and distance units are in pixels (of course). The curvature is very small, so we multiply by 10^6 and express the constraints on the model curvatures in micro-units. (2) This sets five curvature thresholds and a slope threshold: * the maximum absolute value of the vertical disparity line curvatures * the minimum absolute value of the largest difference in vertical disparity line curvatures (Use a value of 0 to accept all models.) * the maximum absolute value of the largest difference in vertical disparity line curvatures * the maximum absolute value of the left and right edge curvature for the horizontal disparity * the maximum absolute value of the difference between left and right edge curvature for the horizontal disparity all in micro-units, for dewarping to take place. Use -1 for default values. (3) An image with a line curvature less than about 0.00001 has fairly straight textlines. This is 10 micro-units. (4) For example, if == 100, this would prevent dewarping if any of the lines has a curvature exceeding 100 micro-units. A model having maximum line curvature larger than about 150 micro-units should probably not be used. (5) A model having a left or right edge curvature larger than about 100 micro-units should probably not be used.

l_int32 dewarpaSetMaxDistance ( L_DEWARPA dewa,
l_int32  maxdist 
)

dewarpaSetMaxDistance()

Input: dewa maxdist (for using ref models) Return: 0 if OK, 1 on error

Notes: (1) This sets the maxdist field.

l_int32 dewarpaUseBothArrays ( L_DEWARPA dewa,
l_int32  useboth 
)

dewarpaUseBothArrays()

Input: dewa useboth (0 for false, 1 for true) Return: 0 if OK, 1 on error

Notes: (1) This sets the useboth field. If set, this will attempt to apply both vertical and horizontal disparity arrays. Note that a model with only a vertical disparity array will always be valid.

l_int32 dewarpaWrite ( const char *  filename,
L_DEWARPA dewa 
)

dewarpaWrite()

Input: filename dewa Return: 0 if OK, 1 on error

l_int32 dewarpaWriteStream ( FILE *  fp,
L_DEWARPA dewa 
)

dewarpaWriteStream()

Input: stream (opened for "wb") dewa Return: 0 if OK, 1 on error

L_DEWARP* dewarpCreate ( PIX pixs,
l_int32  pageno 
)

dewarpCreate()

Input: pixs (1 bpp) pageno (page number) Return: dew (or null on error)

Notes: (1) The input pixs is either full resolution or 2x reduced. (2) The page number is typically 0-based. If scanned from a book, the even pages are usually on the left. Disparity arrays built for even pages should only be applied to even pages.

L_DEWARP* dewarpCreateRef ( l_int32  pageno,
l_int32  refpage 
)

dewarpCreateRef()

Input: pageno (this page number) refpage (page number of dewarp disparity arrays to be used) Return: dew (or null on error)

Notes: (1) This specifies which dewarp struct should be used for the given page. It is placed in dewarpa for pages for which no model can be built. (2) This page and the reference page have the same parity and the reference page is the closest page with a disparity model to this page.

void dewarpDestroy ( L_DEWARP **  pdew)

dewarpDestroy()

Input: &dew (<will be="" set="" to="" null="" before="" returning>="">) Return: void

L_DEWARP* dewarpRead ( const char *  filename)

dewarpRead()

Input: filename Return: dew, or null on error

L_DEWARP* dewarpReadStream ( FILE *  fp)

dewarpReadStream()

Input: stream Return: dew, or null on error

Notes: (1) The dewarp struct is stored in minimized format, with only subsampled disparity arrays. (2) The sampling and extra horizontal disparity parameters are stored here. During generation of the dewarp struct, they are passed in from the dewarpa. In readback, it is assumed that they are (a) the same for each page and (b) the same as the values used to create the dewarpa.

l_int32 dewarpWrite ( const char *  filename,
L_DEWARP dew 
)

dewarpWrite()

Input: filename dew Return: 0 if OK, 1 on error

l_int32 dewarpWriteStream ( FILE *  fp,
L_DEWARP dew 
)

dewarpWriteStream()

Input: stream (opened for "wb") dew Return: 0 if OK, 1 on error

Notes: (1) This should not be written if there is no sampled vertical disparity array, which means that no model has been built for this page.


Переменные

const l_int32 DEFAULT_ARRAY_SAMPLING = 30 [static]
const l_int32 DEFAULT_MAX_DIFF_EDGECURV = 40 [static]
const l_int32 DEFAULT_MAX_DIFF_LINECURV = 200 [static]
const l_int32 DEFAULT_MAX_EDGECURV = 50 [static]
const l_int32 DEFAULT_MAX_EDGESLOPE = 80 [static]
const l_int32 DEFAULT_MAX_LINECURV = 180 [static]
const l_int32 DEFAULT_MAX_REF_DIST = 16 [static]
const l_int32 DEFAULT_MIN_DIFF_LINECURV = 0 [static]
const l_int32 DEFAULT_MIN_LINES = 15 [static]
const l_int32 INITIAL_PTR_ARRAYSIZE = 20 [static]
const l_int32 MAX_PTR_ARRAYSIZE = 10000 [static]
const l_int32 MIN_ARRAY_SAMPLING = 8 [static]
const l_int32 MIN_MIN_LINES = 4 [static]