src/dewarp.c
FPIX *
fpixBuildHorizontalDisparity(FPIX      *fpixv,
                             l_float32  factor,
                             l_int32   *pextraw)
{
l_int32     w, h, i, j, fw, wpl, maxloc;
l_float32   val1, val2, vdisp, vdisp0, maxval;
l_float32  *data, *line, *fadiff;
NUMA       *nadiff;
FPIX       *fpixh;

    PROCNAME("fpixBuildHorizontalDisparity");

    if (!fpixv)
        return (FPIX *)ERROR_PTR("fpixv not defined", procName, NULL);
    if (!pextraw)
        return (FPIX *)ERROR_PTR("&extraw not defined", procName, NULL);
    if (factor == 0.0)
        factor = DEFAULT_SLOPE_FACTOR;

        /* Estimate horizontal disparity from the vertical disparity
         * difference between the top and bottom, normalized to the
         * image height.  Add the maximum value to the width of the
         * output image, so that all src pixels can be mapped
         * into the dest. */
    fpixGetDimensions(fpixv, &w, &h);
    nadiff = numaCreate(w);
    for (j = 0; j < w; j++) {
        fpixGetPixel(fpixv, j, 0, &val1);
        fpixGetPixel(fpixv, j, h - 1, &val2);
        vdisp = factor * (val2 - val1) / (l_float32)h;
        if (j == 0) vdisp0 = vdisp;
        vdisp = vdisp0 - vdisp;
        numaAddNumber(nadiff, vdisp);
    }
    numaGetMax(nadiff, &maxval, &maxloc);
    *pextraw = (l_int32)(maxval + 0.5);

    fw = w + *pextraw;
    fpixh = fpixCreate(fw, h);
    data = fpixGetData(fpixh);
    wpl = fpixGetWpl(fpixh);
    fadiff = numaGetFArray(nadiff, L_NOCOPY);
    for (i = 0; i < h; i++) {
        line = data + i * wpl;
        for (j = 0; j < fw; j++) {
            if (j < maxloc)   /* this may not work for even pages */
                line[j] = fadiff[j];
            else  /* keep it at the max value the rest of the way across */
                line[j] = maxval;
        }
    }

    numaDestroy(&nadiff);
    return fpixh;
}
/*!
 *  fpixBuildHorizontalDisparity()
 *
 *      Input:  fpixv (vertical disparity model)
 *              factor (conversion factor for vertical disparity slope;
 *                      use 0 for default)
 *              &extraw (<return> extra width to be added to dewarped pix)
 *      Return: fpixh, or null on error
 *
 *  Notes:
 *      (1) This takes the difference in vertical disparity at top
 *          and bottom of the image, and converts it to an assumed
 *          horizontal disparity.
 */
fpixBuildHorizontalDisparity()
Input:  fpixv (vertical disparity model)
factor (conversion factor for vertical disparity slope;
use 0 for default)
&extraw ( extra width to be added to dewarped pix)
Return: fpixh, or null on error

(1) This takes the difference in vertical disparity at top
and bottom of the image, and converts it to an assumed
horizontal disparity.
fpixBuildHorizontalDisparity () Input : fpixv ( vertical disparity model ) factor ( conversion factor for vertical disparity slope ; use 0 for default ) &extraw ( extra width to be added to dewarped pix ) Return : fpixh or null on error ( 1 ) This takes the difference in vertical disparity at top and bottom of the image and converts it to an assumed horizontal disparity .
FPIX *
fpixBuildHorizontalDisparity(FPIX      *fpixv,
                             l_float32  factor,
                             l_int32   *pextraw)
{
l_int32     w, h, i, j, fw, wpl, maxloc;
l_float32   val1, val2, vdisp, vdisp0, maxval;
l_float32  *data, *line, *fadiff;
NUMA       *nadiff;
FPIX       *fpixh;
    PROCNAME("fpixBuildHorizontalDisparity");
    if (!fpixv)
        return (FPIX *)ERROR_PTR("fpixv not defined", procName, NULL);
    if (!pextraw)
        return (FPIX *)ERROR_PTR("&extraw not defined", procName, NULL);
    if (factor == 0.0)
        factor = DEFAULT_SLOPE_FACTOR;
    fpixGetDimensions(fpixv, &w, &h);
    nadiff = numaCreate(w);
    for (j = 0; j < w; j++) {
        fpixGetPixel(fpixv, j, 0, &val1);
        fpixGetPixel(fpixv, j, h - 1, &val2);
        vdisp = factor * (val2 - val1) / (l_float32)h;
        if (j == 0) vdisp0 = vdisp;
        vdisp = vdisp0 - vdisp;
        numaAddNumber(nadiff, vdisp);
    }
    numaGetMax(nadiff, &maxval, &maxloc);
    *pextraw = (l_int32)(maxval + 0.5);
    fw = w + *pextraw;
    fpixh = fpixCreate(fw, h);
    data = fpixGetData(fpixh);
    wpl = fpixGetWpl(fpixh);
    fadiff = numaGetFArray(nadiff, L_NOCOPY);
    for (i = 0; i < h; i++) {
        line = data + i * wpl;
        for (j = 0; j < fw; j++) {
            if (j < maxloc)   
                line[j] = fadiff[j];
            else  
                line[j] = maxval;
        }
    }
    numaDestroy(&nadiff);
    return fpixh;
}
FPIX * fpixBuildHorizontalDisparity ( FPIX * fpixv , l_float32 factor , l_int32 * pextraw ) { l_int32 w , h , i , j , fw , wpl , maxloc ; l_float32 val1 , val2 , vdisp , vdisp0 , maxval ; l_float32 * data , * line , * fadiff ; NUMA * nadiff ; FPIX * fpixh ; PROCNAME ( " " ) ; if ( ! fpixv ) return ( FPIX * ) ERROR_PTR ( " " , procName , NULL ) ; if ( ! pextraw ) return ( FPIX * ) ERROR_PTR ( " " , procName , NULL ) ; if ( factor == 0.0 ) factor = DEFAULT_SLOPE_FACTOR ; fpixGetDimensions ( fpixv , & w , & h ) ; nadiff = numaCreate ( w ) ; for ( j = 0 ; j < w ; j ++ ) { fpixGetPixel ( fpixv , j , 0 , & val1 ) ; fpixGetPixel ( fpixv , j , h - 1 , & val2 ) ; vdisp = factor * ( val2 - val1 ) / ( l_float32 ) h ; if ( j == 0 ) vdisp0 = vdisp ; vdisp = vdisp0 - vdisp ; numaAddNumber ( nadiff , vdisp ) ; } numaGetMax ( nadiff , & maxval , & maxloc ) ; * pextraw = ( l_int32 ) ( maxval + 0.5 ) ; fw = w + * pextraw ; fpixh = fpixCreate ( fw , h ) ; data = fpixGetData ( fpixh ) ; wpl = fpixGetWpl ( fpixh ) ; fadiff = numaGetFArray ( nadiff , L_NOCOPY ) ; for ( i = 0 ; i < h ; i ++ ) { line = data + i * wpl ; for ( j = 0 ; j < fw ; j ++ ) { if ( j < maxloc ) line [ j ] = fadiff [ j ] ; else line [ j ] = maxval ; } } numaDestroy ( & nadiff ) ; return fpixh ; }
fpixBuildHorizontalDisparity()
      Input:  fpixv (vertical disparity model)
              factor (conversion factor for vertical disparity slope;
                      use 0 for default)
              &extraw (<return> extra width to be added to dewarped pix)
      Return: fpixh, or null on error
fpixBuildHorizontalDisparity () Input : fpixv ( vertical disparity model ) factor ( conversion factor for vertical disparity slope ; use 0 for default ) &extraw ( <return > extra width to be added to dewarped pix ) Return : fpixh or null on error
/* Estimate horizontal disparity from the vertical disparity
         * difference between the top and bottom, normalized to the
         * image height.  Add the maximum value to the width of the
         * output image, so that all src pixels can be mapped
         * into the dest. */ /* this may not work for even pages */ /* keep it at the max value the rest of the way across */