Leptonica  1.82.0
Image processing and image analysis suite
dewarp3.c File Reference
#include <math.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

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_ok dewarpaApplyDisparity (L_DEWARPA *dewa, l_int32 pageno, PIX *pixs, l_int32 grayin, l_int32 x, l_int32 y, PIX **ppixd, const char *debugfile)
 
l_ok 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_ok dewarpMinimize (L_DEWARP *dew)
 
l_ok dewarpPopulateFullRes (L_DEWARP *dew, PIX *pix, l_int32 x, l_int32 y)
 

Detailed Description

   Applying and stripping the page disparity model
     Apply disparity array to pix
         l_int32            dewarpaApplyDisparity()
         static l_int32     dewarpaApplyInit()
         static PIX        *pixApplyVertDisparity()
         static PIX        *pixApplyHorizDisparity()
     Apply disparity array to boxa
         l_int32            dewarpaApplyDisparityBoxa()
         static BOXA       *boxaApplyDisparity()
     Stripping out data and populating full res disparity
         l_int32            dewarpMinimize()
         l_int32            dewarpPopulateFullRes()
     Static functions not presently in use
         static FPIX       *fpixSampledDisparity()
         static FPIX       *fpixExtraHorizDisparity()
 

Definition in file dewarp3.c.

Function Documentation

◆ boxaApplyDisparity()

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

boxaApplyDisparity()

Parameters
[in]dew
[in]boxa
[in]directionL_HORIZ or L_VERT
[in]mapdir1 if mapping forward from original to dewarped; 0 if backward
Returns
boxad modified by the disparity, or NULL on error

Definition at line 645 of file dewarp3.c.

References L_Dewarp::h, and L_Dewarp::w.

Referenced by dewarpaApplyDisparityBoxa().

◆ dewarpaApplyDisparity()

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

dewarpaApplyDisparity()

Parameters
[in]dewa
[in]pagenoof page model to be used; may be a ref model
[in]pixsimage to be modified; can be 1, 8 or 32 bpp
[in]grayingray value, from 0 to 255, for pixels brought in; use -1 to use pixels on the boundary of pixs
[in]x,yorigin for generation of disparity arrays
[out]ppixddisparity corrected image
[in]debugfileuse NULL to skip writing this
Returns
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 pageno, this will use the model for
         'refpage' and put the result in the dew for pageno.
     (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 pageno.
         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.

Definition at line 116 of file dewarp3.c.

References L_Dewarp::dewa, dewarpaApplyInit(), dewarpMinimize(), lept_mkdir(), lept_rmdir(), L_Dewarp::pageno, pixApplyVertDisparity(), pixClone(), pixDestroy(), and L_Dewarp::pixs.

Referenced by dewarpShowResults(), and dewarpSinglePageRun().

◆ dewarpaApplyDisparityBoxa()

l_ok 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()

Parameters
[in]dewa
[in]pagenoof page model to be used; may be a ref model
[in]pixsinitial pix reference; for alignment and debugging
[in]boxasboxa to be mapped
[in]mapdir1 if mapping forward from original to dewarped; 0 if backward
[in]x,yorigin for generation of disparity arrays with respect to the source region
[out]pboxaddisparity corrected boxa
[in]debugfileuse NULL to skip writing this
Returns
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 pageno, this will use the model for
         'refpage' and put the result in the dew for pageno.
     (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.

Definition at line 539 of file dewarp3.c.

References boxaApplyDisparity(), boxaCopy(), L_Dewarp::dewa, dewarpaApplyInit(), L_CLONE, L_Dewarp::pageno, and L_Dewarp::pixs.

◆ dewarpaApplyInit()

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()

Parameters
[in]dewa
[in]pagenoof page model to be used; may be a ref model
[in]pixsimage to be modified; can be 1, 8 or 32 bpp
[in]x,yorigin for generation of disparity arrays
[out]pdewdewarp to be used for this page
[in]debugfileuse NULL to skip writing this
Returns
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 dew contains the model to be used for this page
         image.  The dew is owned by dewa; do not destroy.
     (3) If both the 'useboth' and 'check_columns' fields are true,
         this checks for multiple text columns and if found, sets
         the 'skip_horiz' field in the dew for this page.

Definition at line 216 of file dewarp3.c.

References L_Dewarpa::check_columns, L_Dewarp::debug, L_Dewarp::dewa, dewarpaGetDewarp(), dewarpaInsertRefModels(), dewarpPopulateFullRes(), L_Dewarp::hasref, L_Dewarpa::maxpage, L_Dewarpa::modelsready, L_Dewarp::pageno, pixConvertTo1(), pixCountTextColumns(), pixDestroy(), L_Dewarp::pixs, L_Dewarp::refpage, L_Dewarp::skip_horiz, L_Dewarpa::useboth, and L_Dewarp::vvalid.

Referenced by dewarpaApplyDisparity(), and dewarpaApplyDisparityBoxa().

◆ dewarpMinimize()

l_ok dewarpMinimize ( L_DEWARP dew)

dewarpMinimize()

Parameters
[in]dew
Returns
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.

Definition at line 731 of file dewarp3.c.

References L_Dewarp::dewa, dewarpaGetDewarp(), fpixDestroy(), L_Dewarp::fullhdispar, L_Dewarp::fullvdispar, L_Dewarp::hasref, L_Dewarp::nacurves, L_Dewarp::namidys, numaDestroy(), pixDestroy(), L_Dewarp::pixs, and L_Dewarp::refpage.

Referenced by dewarpaApplyDisparity(), and dewarpaShowArrays().

◆ dewarpPopulateFullRes()

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

dewarpPopulateFullRes()

Parameters
[in]dew
[in]pix[optional], to give size of actual image
[in]x,yorigin for generation of disparity arrays
Returns
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.

Definition at line 787 of file dewarp3.c.

References fpixAddMultConstant(), fpixAddSlopeBorder(), fpixCopy(), fpixDestroy(), fpixGetDimensions(), fpixScaleByInteger(), L_Dewarp::fullhdispar, L_Dewarp::fullvdispar, L_Dewarp::h, L_Dewarp::nx, L_Dewarp::ny, pixGetDimensions(), L_Dewarp::redfactor, L_Dewarp::samphdispar, L_Dewarp::sampling, L_Dewarp::sampvdispar, L_Dewarp::skip_horiz, and L_Dewarp::w.

Referenced by dewarpaApplyInit(), dewarpaShowArrays(), and dewarpDebug().

◆ pixApplyHorizDisparity()

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

pixApplyHorizDisparity()

Parameters
[in]dew
[in]pixs1, 8 or 32 bpp
[in]grayingray value, from 0 to 255, for pixels brought in; use -1 to use pixels on the boundary of pixs
Returns
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 pixs.

Definition at line 420 of file dewarp3.c.

References fpixGetData(), fpixGetDimensions(), L_Dewarp::fullhdispar, L_Dewarp::h, lept_stderr(), pixCreateTemplate(), pixGetData(), pixGetDimensions(), L_Dewarp::pixs, pixSetAllGray(), and L_Dewarp::w.

◆ pixApplyVertDisparity()

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

pixApplyVertDisparity()

Parameters
[in]dew
[in]pixs1, 8 or 32 bpp
[in]grayingray value, from 0 to 255, for pixels brought in; use -1 to use pixels on the boundary of pixs
Returns
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.

Definition at line 310 of file dewarp3.c.

References fpixGetData(), fpixGetDimensions(), L_Dewarp::fullvdispar, L_Dewarp::h, lept_stderr(), pixCreateTemplate(), pixGetData(), pixGetDimensions(), L_Dewarp::pixs, pixSetAllGray(), and L_Dewarp::w.

Referenced by dewarpaApplyDisparity().