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

Функции

static l_int32 dewarpaApplyInit (L_DEWARPA *dewa, l_int32 pageno, PIX *pixs, l_int32 x, l_int32 y, L_DEWARP **pdew, const char *debugfile)
static PIXpixApplyVertDisparity (L_DEWARP *dew, PIX *pixs, l_int32 grayin)
static PIXpixApplyHorizDisparity (L_DEWARP *dew, PIX *pixs, l_int32 grayin)
static BOXAboxaApplyDisparity (L_DEWARP *dew, BOXA *boxa, l_int32 direction, l_int32 mapdir)
l_int32 dewarpaApplyDisparity (L_DEWARPA *dewa, l_int32 pageno, PIX *pixs, l_int32 grayin, l_int32 x, l_int32 y, PIX **ppixd, const char *debugfile)
l_int32 dewarpaApplyDisparityBoxa (L_DEWARPA *dewa, l_int32 pageno, PIX *pixs, BOXA *boxas, l_int32 mapdir, l_int32 x, l_int32 y, BOXA **pboxad, const char *debugfile)
l_int32 dewarpMinimize (L_DEWARP *dew)
l_int32 dewarpPopulateFullRes (L_DEWARP *dew, PIX *pix, l_int32 x, l_int32 y)

Функции

static BOXA * boxaApplyDisparity ( L_DEWARP dew,
BOXA boxa,
l_int32  direction,
l_int32  mapdir 
) [static]

boxaApplyDisparity()

Input: dew boxa direction (L_HORIZ or L_VERT) mapdir (1 if mapping forward from original to dewarped; 0 if backward) Return: boxad (modified by the disparity), or null on error

l_int32 dewarpaApplyDisparity ( L_DEWARPA dewa,
l_int32  pageno,
PIX pixs,
l_int32  grayin,
l_int32  x,
l_int32  y,
PIX **  ppixd,
const char *  debugfile 
)

dewarpaApplyDisparity()

Input: dewa pageno (of page model to be used; may be a ref model) pixs (image to be modified; can be 1, 8 or 32 bpp) grayin (gray value, from 0 to 255, for pixels brought in; use -1 to use pixels on the boundary of pixs) x, y (origin for generation of disparity arrays) &pixd (<return> disparity corrected image) debugfile (use null to skip writing this) Return: 0 if OK, 1 on error (no models or ref models available)

Notes: (1) This applies the disparity arrays to the specified image. (2) Specify gray color for pixels brought in from the outside: 0 is black, 255 is white. Use -1 to select pixels from the boundary of the source image. (3) If the models and ref models have not been validated, this will do so by calling dewarpaInsertRefModels(). (4) This works with both stripped and full resolution page models. If the full res disparity array(s) are missing, they are remade. (5) The caller must handle errors that are returned because there are no valid models or ref models for the page -- typically by using the input pixs. (6) If there is no model for , this will use the model for 'refpage' and put the result in the dew for . (7) This populates the full resolution disparity arrays if necessary. If x and/or y are positive, they are used, in conjunction with pixs, to determine the required slope-based extension of the full resolution disparity arrays in each direction. When (x,y) == (0,0), all extension is to the right and down. Nonzero values of (x,y) are useful for dewarping when pixs is deliberately undercropped. (8) Important: when applying disparity to a number of images, after calling this function and saving the resulting pixd, you should call dewarpMinimize(dew) on the dew for . This will remove pixs and pixd (or their clones) stored in dew, as well as the full resolution disparity arrays. Together, these hold approximately 16 bytes for each pixel in pixs.

l_int32 dewarpaApplyDisparityBoxa ( L_DEWARPA dewa,
l_int32  pageno,
PIX pixs,
BOXA boxas,
l_int32  mapdir,
l_int32  x,
l_int32  y,
BOXA **  pboxad,
const char *  debugfile 
)

dewarpaApplyDisparityBoxa()

Input: dewa pageno (of page model to be used; may be a ref model) pixs (initial pix reference; for alignment and debugging) boxas (boxa to be mapped) mapdir (1 if mapping forward from original to dewarped; 0 if backward) x, y (origin for generation of disparity arrays with respect to the source region) &boxad (<return> disparity corrected boxa) debugfile (use null to skip writing this) Return: 0 if OK, 1 on error (no models or ref models available)

Notes: (1) This applies the disparity arrays in one of two mapping directions to the specified boxa. It can be used in the backward direction to locate a box in the original coordinates that would have been dewarped to to the specified image. (2) If there is no model for , this will use the model for 'refpage' and put the result in the dew for . (3) This works with both stripped and full resolution page models. If the full res disparity array(s) are missing, they are remade. (4) If an error occurs, a copy of the input boxa is returned.

static l_int32 dewarpaApplyInit ( L_DEWARPA dewa,
l_int32  pageno,
PIX pixs,
l_int32  x,
l_int32  y,
L_DEWARP **  pdew,
const char *  debugfile 
) [static]

dewarpaApplyInit()

Input: dewa pageno (of page model to be used; may be a ref model) pixs (image to be modified; can be 1, 8 or 32 bpp) x, y (origin for generation of disparity arrays) &pdew (<return> dewarp to be used for this page debugfile (use null to skip writing this) Return: 0 if OK, 1 on error (no models or ref models available)

Notes: (1) This prepares pixs for being dewarped. It returns 1 if no dewarping model exists. (2) The returned contains the model to be used for this page image. The is owned by dewa; do not destroy. (3) See dewarpApplyDisparity() for other details on inputs.

dewarpMinimize()

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

Notes: (1) This removes all data that is not needed for serialization. It keeps the subsampled disparity array(s), so the full resolution arrays can be reconstructed.

l_int32 dewarpPopulateFullRes ( L_DEWARP dew,
PIX pix,
l_int32  x,
l_int32  y 
)

dewarpPopulateFullRes()

Input: dew pix (<optional>, to give size of actual image) x, y (origin for generation of disparity arrays) Return: 0 if OK, 1 on error

Notes: (1) If the full resolution vertical and horizontal disparity arrays do not exist, they are built from the subsampled ones. (2) If pixs is not given, the size of the arrays is determined by the original image from which the sampled version was generated. Any values of (x,y) are ignored. (3) If pixs is given, the full resolution disparity arrays must be large enough to accommodate it. (a) If the arrays do not exist, the value of (x,y) determines the origin of the full resolution arrays without extension, relative to pixs. Thus, (x,y) gives the amount of slope extension in (left, top). The (right, bottom) extension is then determined by the size of pixs and (x,y); the values should never be < 0. (b) If the arrays exist and pixs is too large, the existing full res arrays are destroyed and new ones are made, again using (x,y) to determine the extension in the four directions.

static PIX * pixApplyHorizDisparity ( L_DEWARP dew,
PIX pixs,
l_int32  grayin 
) [static]

pixApplyHorizDisparity()

Input: dew pixs (1, 8 or 32 bpp) grayin (gray value, from 0 to 255, for pixels brought in; use -1 to use pixels on the boundary of pixs) Return: pixd (modified to remove horizontal disparity if possible), or null on error.

Notes: (1) This applies the horizontal disparity array to the specified image. (2) Specify gray color for pixels brought in from the outside: 0 is black, 255 is white. Use -1 to select pixels from the boundary of the source image. (3) The input pixs has already been corrected for vertical disparity. If the horizontal disparity array doesn't exist, this returns a clone of .

static PIX * pixApplyVertDisparity ( L_DEWARP dew,
PIX pixs,
l_int32  grayin 
) [static]

pixApplyVertDisparity()

Input: dew pixs (1, 8 or 32 bpp) grayin (gray value, from 0 to 255, for pixels brought in; use -1 to use pixels on the boundary of pixs) Return: pixd (modified to remove vertical disparity), or null on error

Notes: (1) This applies the vertical disparity array to the specified image. For src pixels above the image, we use the pixels in the first raster line. (2) Specify gray color for pixels brought in from the outside: 0 is black, 255 is white. Use -1 to select pixels from the boundary of the source image.