src/jbclass.c
l_int32
jbGetULCorners(JBCLASSER  *classer,
               PIX        *pixs,
               BOXA       *boxa)
{
l_int32    i, baseindex, index, n, iclass, idelx, idely, x, y, dx, dy;
l_int32   *sumtab;
l_float32  x1, x2, y1, y2, delx, dely;
BOX       *box;
NUMA      *naclass;
PIX       *pixt;
PTA       *ptac, *ptact, *ptaul;

    PROCNAME("jbGetULCorners");

    if (!classer)
        return ERROR_INT("classer not defined", procName, 1);
    if (!pixs)
        return ERROR_INT("pixs not defined", procName, 1);
    if (!boxa)
        return ERROR_INT("boxa not defined", procName, 1);

    n = boxaGetCount(boxa);
    ptaul = classer->ptaul;
    naclass = classer->naclass;
    ptac = classer->ptac;
    ptact = classer->ptact;
    baseindex = classer->baseindex;  /* num components before this page */
    sumtab = makePixelSumTab8();
    for (i = 0; i < n; i++) {
        index = baseindex + i;
        ptaGetPt(ptac, index, &x1, &y1);
        numaGetIValue(naclass, index, &iclass);
        ptaGetPt(ptact, iclass, &x2, &y2);
        delx = x2 - x1;
        dely = y2 - y1;
        if (delx >= 0)
            idelx = (l_int32)(delx + 0.5);
        else
            idelx = (l_int32)(delx - 0.5);
        if (dely >= 0)
            idely = (l_int32)(dely + 0.5);
        else
            idely = (l_int32)(dely - 0.5);
        if ((box = boxaGetBox(boxa, i, L_CLONE)) == NULL)
            return ERROR_INT("box not found", procName, 1);
        boxGetGeometry(box, &x, &y, NULL, NULL);

            /* Get final increments dx and dy for best alignment */
        pixt = pixaGetPix(classer->pixat, iclass, L_CLONE);
        finalPositioningForAlignment(pixs, x, y, idelx, idely,
                                     pixt, sumtab, &dx, &dy);
/*        if (i % 20 == 0)
            fprintf(stderr, "dx = %d, dy = %d\n", dx, dy); */
        ptaAddPt(ptaul, x - idelx + dx, y - idely + dy);
        boxDestroy(&box);
        pixDestroy(&pixt);
    }

    FREE(sumtab);
    return 0;
}
/*!
 *  jbGetULCorners()
 *
 *      Input:  jbclasser
 *              pixs (full res image)
 *              boxa (of c.c. bounding rectangles for this page)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) This computes the ptaul field, which has the global UL corners,
 *          adjusted for each specific component, so that each component
 *          can be replaced by the template for its class and have the
 *          centroid in the template in the same position as the
 *          centroid of the original connected component.  It is important
 *          that this be done properly to avoid a wavy baseline in the
 *          result.
 *      (2) The array fields ptac and ptact give the centroids of
 *          those components relative to the UL corner of each component.
 *          Here, we compute the difference in each component, round to
 *          nearest integer, and correct the box->x and box->y by
 *          the appropriate integral difference.
 *      (3) The templates and stored instances are all bordered.
 */
jbGetULCorners()
Input:  jbclasser
pixs (full res image)
boxa (of c.c. bounding rectangles for this page)
Return: 0 if OK, 1 on error

(1) This computes the ptaul field, which has the global UL corners,
adjusted for each specific component, so that each component
can be replaced by the template for its class and have the
centroid in the template in the same position as the
centroid of the original connected component.  It is important
that this be done properly to avoid a wavy baseline in the
result.
(2) The array fields ptac and ptact give the centroids of
those components relative to the UL corner of each component.
Here, we compute the difference in each component, round to
nearest integer, and correct the box->x and box->y by
the appropriate integral difference.
(3) The templates and stored instances are all bordered.
jbGetULCorners () Input : jbclasser pixs ( full res image ) boxa ( of c . c . bounding rectangles for this page ) Return : 0 if OK 1 on error ( 1 ) This computes the ptaul field which has the global UL corners adjusted for each specific component so that each component can be replaced by the template for its class and have the centroid in the template in the same position as the centroid of the original connected component . It is important that this be done properly to avoid a wavy baseline in the result . ( 2 ) The array fields ptac and ptact give the centroids of those components relative to the UL corner of each component . Here we compute the difference in each component round to nearest integer and correct the box - > x and box - > y by the appropriate integral difference . ( 3 ) The templates and stored instances are all bordered .
l_int32
jbGetULCorners(JBCLASSER  *classer,
               PIX        *pixs,
               BOXA       *boxa)
{
l_int32    i, baseindex, index, n, iclass, idelx, idely, x, y, dx, dy;
l_int32   *sumtab;
l_float32  x1, x2, y1, y2, delx, dely;
BOX       *box;
NUMA      *naclass;
PIX       *pixt;
PTA       *ptac, *ptact, *ptaul;
    PROCNAME("jbGetULCorners");
    if (!classer)
        return ERROR_INT("classer not defined", procName, 1);
    if (!pixs)
        return ERROR_INT("pixs not defined", procName, 1);
    if (!boxa)
        return ERROR_INT("boxa not defined", procName, 1);
    n = boxaGetCount(boxa);
    ptaul = classer->ptaul;
    naclass = classer->naclass;
    ptac = classer->ptac;
    ptact = classer->ptact;
    baseindex = classer->baseindex;  
    sumtab = makePixelSumTab8();
    for (i = 0; i < n; i++) {
        index = baseindex + i;
        ptaGetPt(ptac, index, &x1, &y1);
        numaGetIValue(naclass, index, &iclass);
        ptaGetPt(ptact, iclass, &x2, &y2);
        delx = x2 - x1;
        dely = y2 - y1;
        if (delx >= 0)
            idelx = (l_int32)(delx + 0.5);
        else
            idelx = (l_int32)(delx - 0.5);
        if (dely >= 0)
            idely = (l_int32)(dely + 0.5);
        else
            idely = (l_int32)(dely - 0.5);
        if ((box = boxaGetBox(boxa, i, L_CLONE)) == NULL)
            return ERROR_INT("box not found", procName, 1);
        boxGetGeometry(box, &x, &y, NULL, NULL);
        pixt = pixaGetPix(classer->pixat, iclass, L_CLONE);
        finalPositioningForAlignment(pixs, x, y, idelx, idely,
                                     pixt, sumtab, &dx, &dy);
        ptaAddPt(ptaul, x - idelx + dx, y - idely + dy);
        boxDestroy(&box);
        pixDestroy(&pixt);
    }
    FREE(sumtab);
    return 0;
}
l_int32 jbGetULCorners ( JBCLASSER * classer , PIX * pixs , BOXA * boxa ) { l_int32 i , baseindex , index , n , iclass , idelx , idely , x , y , dx , dy ; l_int32 * sumtab ; l_float32 x1 , x2 , y1 , y2 , delx , dely ; BOX * box ; NUMA * naclass ; PIX * pixt ; PTA * ptac , * ptact , * ptaul ; PROCNAME ( " " ) ; if ( ! classer ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! pixs ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! boxa ) return ERROR_INT ( " " , procName , 1 ) ; n = boxaGetCount ( boxa ) ; ptaul = classer -> ptaul ; naclass = classer -> naclass ; ptac = classer -> ptac ; ptact = classer -> ptact ; baseindex = classer -> baseindex ; sumtab = makePixelSumTab8 ( ) ; for ( i = 0 ; i < n ; i ++ ) { index = baseindex + i ; ptaGetPt ( ptac , index , & x1 , & y1 ) ; numaGetIValue ( naclass , index , & iclass ) ; ptaGetPt ( ptact , iclass , & x2 , & y2 ) ; delx = x2 - x1 ; dely = y2 - y1 ; if ( delx >= 0 ) idelx = ( l_int32 ) ( delx + 0.5 ) ; else idelx = ( l_int32 ) ( delx - 0.5 ) ; if ( dely >= 0 ) idely = ( l_int32 ) ( dely + 0.5 ) ; else idely = ( l_int32 ) ( dely - 0.5 ) ; if ( ( box = boxaGetBox ( boxa , i , L_CLONE ) ) == NULL ) return ERROR_INT ( " " , procName , 1 ) ; boxGetGeometry ( box , & x , & y , NULL , NULL ) ; pixt = pixaGetPix ( classer -> pixat , iclass , L_CLONE ) ; finalPositioningForAlignment ( pixs , x , y , idelx , idely , pixt , sumtab , & dx , & dy ) ; ptaAddPt ( ptaul , x - idelx + dx , y - idely + dy ) ; boxDestroy ( & box ) ; pixDestroy ( & pixt ) ; } FREE ( sumtab ) ; return 0 ; }
jbGetULCorners()
      Input:  jbclasser
              pixs (full res image)
              boxa (of c.c.
jbGetULCorners () Input : jbclasser pixs ( full res image ) boxa ( of c . c .
/* num components before this page */ /* Get final increments dx and dy for best alignment */ /*        if (i % 20 == 0)
            fprintf(stderr, "dx = %d, dy = %d\n", dx, dy); */