src/jbclass.c
PIXA *
jbAccumulateComposites(PIXAA  *pixaa,
                       NUMA  **pna,
                       PTA   **pptat)
{
l_int32    n, nt, i, j, d, minw, maxw, minh, maxh, xdiff, ydiff;
l_float32  x, y, xave, yave;
NUMA      *na;
PIX       *pix, *pixt1, *pixt2, *pixsum;
PIXA      *pixa, *pixad;
PTA       *ptat, *pta;

    PROCNAME("jbAccumulateComposites");

    if (!pptat)
        return (PIXA *)ERROR_PTR("&ptat not defined", procName, NULL);
    *pptat = NULL;
    if (!pna)
        return (PIXA *)ERROR_PTR("&na not defined", procName, NULL);
    *pna = NULL;
    if (!pixaa)
        return (PIXA *)ERROR_PTR("pixaa not defined", procName, NULL);

    n = pixaaGetCount(pixaa);
    if ((ptat = ptaCreate(n)) == NULL)
        return (PIXA *)ERROR_PTR("ptat not made", procName, NULL);
    *pptat = ptat;
    pixad = pixaCreate(n);
    na = numaCreate(n);
    *pna = na;

    for (i = 0; i < n; i++) {
        pixa = pixaaGetPixa(pixaa, i, L_CLONE);
        nt = pixaGetCount(pixa);
        numaAddNumber(na, nt);
        if (nt == 0) {
            L_WARNING("empty pixa found!", procName);
            pixaDestroy(&pixa);
            continue;
        }
        pixaSizeRange(pixa, &minw, &minh, &maxw, &maxh);
        pix = pixaGetPix(pixa, 0, L_CLONE);
        d = pixGetDepth(pix);
        pixDestroy(&pix);
        pixt1 = pixCreate(maxw, maxh, d);
        pixsum = pixInitAccumulate(maxw, maxh, 0);
        pta = pixaCentroids(pixa);

            /* Find the average value of the centroids ... */
        xave = yave = 0;
        for (j = 0; j < nt; j++) {
            ptaGetPt(pta, j, &x, &y);
            xave += x;
            yave += y;
        }
        xave = xave / (l_float32)nt;
        yave = yave / (l_float32)nt;

            /* and place all centroids at their average value */
        for (j = 0; j < nt; j++) {
            pixt2 = pixaGetPix(pixa, j, L_CLONE);
            ptaGetPt(pta, j, &x, &y);
            xdiff = (l_int32)(x - xave);
            ydiff = (l_int32)(y - yave);
            pixClearAll(pixt1);
            pixRasterop(pixt1, xdiff, ydiff, maxw, maxh, PIX_SRC,
                        pixt2, 0, 0);
            pixAccumulate(pixsum, pixt1, L_ARITH_ADD);
            pixDestroy(&pixt2);
        }
        pixaAddPix(pixad, pixsum, L_INSERT);
        ptaAddPt(ptat, xave, yave);

        pixaDestroy(&pixa);
        pixDestroy(&pixt1);
        ptaDestroy(&pta);
    }

    return pixad;
}
/*!
 *  jbAccumulateComposites()
 *
 *      Input:  pixaa (one pixa for each class)
 *              &pna (<return> number of samples used to build each composite)
 *              &ptat (<return> centroids of bordered composites)
 *      Return: pixad (accumulated sum of samples in each class),
 *                     or null on error
 *
 */
jbAccumulateComposites()
Input:  pixaa (one pixa for each class)
&pna ( number of samples used to build each composite)
&ptat ( centroids of bordered composites)
Return: pixad (accumulated sum of samples in each class),
or null on error
jbAccumulateComposites () Input : pixaa ( one pixa for each class ) &pna ( number of samples used to build each composite ) &ptat ( centroids of bordered composites ) Return : pixad ( accumulated sum of samples in each class ) or null on error
PIXA *
jbAccumulateComposites(PIXAA  *pixaa,
                       NUMA  **pna,
                       PTA   **pptat)
{
l_int32    n, nt, i, j, d, minw, maxw, minh, maxh, xdiff, ydiff;
l_float32  x, y, xave, yave;
NUMA      *na;
PIX       *pix, *pixt1, *pixt2, *pixsum;
PIXA      *pixa, *pixad;
PTA       *ptat, *pta;
    PROCNAME("jbAccumulateComposites");
    if (!pptat)
        return (PIXA *)ERROR_PTR("&ptat not defined", procName, NULL);
    *pptat = NULL;
    if (!pna)
        return (PIXA *)ERROR_PTR("&na not defined", procName, NULL);
    *pna = NULL;
    if (!pixaa)
        return (PIXA *)ERROR_PTR("pixaa not defined", procName, NULL);
    n = pixaaGetCount(pixaa);
    if ((ptat = ptaCreate(n)) == NULL)
        return (PIXA *)ERROR_PTR("ptat not made", procName, NULL);
    *pptat = ptat;
    pixad = pixaCreate(n);
    na = numaCreate(n);
    *pna = na;
    for (i = 0; i < n; i++) {
        pixa = pixaaGetPixa(pixaa, i, L_CLONE);
        nt = pixaGetCount(pixa);
        numaAddNumber(na, nt);
        if (nt == 0) {
            L_WARNING("empty pixa found!", procName);
            pixaDestroy(&pixa);
            continue;
        }
        pixaSizeRange(pixa, &minw, &minh, &maxw, &maxh);
        pix = pixaGetPix(pixa, 0, L_CLONE);
        d = pixGetDepth(pix);
        pixDestroy(&pix);
        pixt1 = pixCreate(maxw, maxh, d);
        pixsum = pixInitAccumulate(maxw, maxh, 0);
        pta = pixaCentroids(pixa);
        xave = yave = 0;
        for (j = 0; j < nt; j++) {
            ptaGetPt(pta, j, &x, &y);
            xave += x;
            yave += y;
        }
        xave = xave / (l_float32)nt;
        yave = yave / (l_float32)nt;
        for (j = 0; j < nt; j++) {
            pixt2 = pixaGetPix(pixa, j, L_CLONE);
            ptaGetPt(pta, j, &x, &y);
            xdiff = (l_int32)(x - xave);
            ydiff = (l_int32)(y - yave);
            pixClearAll(pixt1);
            pixRasterop(pixt1, xdiff, ydiff, maxw, maxh, PIX_SRC,
                        pixt2, 0, 0);
            pixAccumulate(pixsum, pixt1, L_ARITH_ADD);
            pixDestroy(&pixt2);
        }
        pixaAddPix(pixad, pixsum, L_INSERT);
        ptaAddPt(ptat, xave, yave);
        pixaDestroy(&pixa);
        pixDestroy(&pixt1);
        ptaDestroy(&pta);
    }
    return pixad;
}
PIXA * jbAccumulateComposites ( PIXAA * pixaa , NUMA * * pna , PTA * * pptat ) { l_int32 n , nt , i , j , d , minw , maxw , minh , maxh , xdiff , ydiff ; l_float32 x , y , xave , yave ; NUMA * na ; PIX * pix , * pixt1 , * pixt2 , * pixsum ; PIXA * pixa , * pixad ; PTA * ptat , * pta ; PROCNAME ( " " ) ; if ( ! pptat ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; * pptat = NULL ; if ( ! pna ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; * pna = NULL ; if ( ! pixaa ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; n = pixaaGetCount ( pixaa ) ; if ( ( ptat = ptaCreate ( n ) ) == NULL ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; * pptat = ptat ; pixad = pixaCreate ( n ) ; na = numaCreate ( n ) ; * pna = na ; for ( i = 0 ; i < n ; i ++ ) { pixa = pixaaGetPixa ( pixaa , i , L_CLONE ) ; nt = pixaGetCount ( pixa ) ; numaAddNumber ( na , nt ) ; if ( nt == 0 ) { L_WARNING ( " " , procName ) ; pixaDestroy ( & pixa ) ; continue ; } pixaSizeRange ( pixa , & minw , & minh , & maxw , & maxh ) ; pix = pixaGetPix ( pixa , 0 , L_CLONE ) ; d = pixGetDepth ( pix ) ; pixDestroy ( & pix ) ; pixt1 = pixCreate ( maxw , maxh , d ) ; pixsum = pixInitAccumulate ( maxw , maxh , 0 ) ; pta = pixaCentroids ( pixa ) ; xave = yave = 0 ; for ( j = 0 ; j < nt ; j ++ ) { ptaGetPt ( pta , j , & x , & y ) ; xave += x ; yave += y ; } xave = xave / ( l_float32 ) nt ; yave = yave / ( l_float32 ) nt ; for ( j = 0 ; j < nt ; j ++ ) { pixt2 = pixaGetPix ( pixa , j , L_CLONE ) ; ptaGetPt ( pta , j , & x , & y ) ; xdiff = ( l_int32 ) ( x - xave ) ; ydiff = ( l_int32 ) ( y - yave ) ; pixClearAll ( pixt1 ) ; pixRasterop ( pixt1 , xdiff , ydiff , maxw , maxh , PIX_SRC , pixt2 , 0 , 0 ) ; pixAccumulate ( pixsum , pixt1 , L_ARITH_ADD ) ; pixDestroy ( & pixt2 ) ; } pixaAddPix ( pixad , pixsum , L_INSERT ) ; ptaAddPt ( ptat , xave , yave ) ; pixaDestroy ( & pixa ) ; pixDestroy ( & pixt1 ) ; ptaDestroy ( & pta ) ; } return pixad ; }
jbAccumulateComposites()
      Input:  pixaa (one pixa for each class)
              &pna (<return> number of samples used to build each composite)
              &ptat (<return> centroids of bordered composites)
      Return: pixad (accumulated sum of samples in each class),
                     or null on error
jbAccumulateComposites () Input : pixaa ( one pixa for each class ) &pna ( <return > number of samples used to build each composite ) &ptat ( <return > centroids of bordered composites ) Return : pixad ( accumulated sum of samples in each class ) or null on error
/* Find the average value of the centroids ... */ /* and place all centroids at their average value */