src/boxfunc5.c
l_ok
boxaMedianDimensions(BOXA     *boxas,
                     l_int32  *pmedw,
                     l_int32  *pmedh,
                     l_int32  *pmedwe,
                     l_int32  *pmedwo,
                     l_int32  *pmedhe,
                     l_int32  *pmedho,
                     NUMA    **pnadelw,
                     NUMA    **pnadelh)
{
l_int32  i, n, bw, bh, medw, medh, medwe, medwo, medhe, medho;
BOXA    *boxae, *boxao;
NUMA    *nadelw, *nadelh;

    PROCNAME("boxaMedianDimensions");

    if (pmedw) *pmedw = 0;
    if (pmedh) *pmedh = 0;
    if (pmedwe) *pmedwe= 0;
    if (pmedwo) *pmedwo= 0;
    if (pmedhe) *pmedhe= 0;
    if (pmedho) *pmedho= 0;
    if (pnadelw) *pnadelw = NULL;
    if (pnadelh) *pnadelh = NULL;
    if (!boxas)
        return ERROR_INT("boxas not defined", procName, 1);
    if (boxaGetValidCount(boxas) < 6)
        return ERROR_INT("need at least 6 valid boxes", procName, 1);

        /* Require at least 3 valid boxes of both types */
    boxaSplitEvenOdd(boxas, 0, &boxae, &boxao);
    if (boxaGetValidCount(boxae) < 3 || boxaGetValidCount(boxao) < 3) {
        boxaDestroy(&boxae);
        boxaDestroy(&boxao);
        return ERROR_INT("don't have 3+ valid boxes of each type", procName, 1);
    }

        /* Get the relevant median widths and heights */
    boxaGetMedianVals(boxas, NULL, NULL, NULL, NULL, &medw, &medh);
    boxaGetMedianVals(boxae, NULL, NULL, NULL, NULL, &medwe, &medhe);
    boxaGetMedianVals(boxao, NULL, NULL, NULL, NULL, &medwo, &medho);
    if (pmedw) *pmedw = medw;
    if (pmedh) *pmedh = medh;
    if (pmedwe) *pmedwe = medwe;
    if (pmedwo) *pmedwo = medwo;
    if (pmedhe) *pmedhe = medhe;
    if (pmedho) *pmedho = medho;

        /* Find the variation from median dimension for each box */
    n = boxaGetCount(boxas);
    nadelw = numaCreate(n);
    nadelh = numaCreate(n);
    for (i = 0; i < n; i++) {
        boxaGetBoxGeometry(boxas, i, NULL, NULL, &bw, &bh);
        if (bw == 0 || bh == 0) {  /* invalid box */
            numaAddNumber(nadelw, 0);
            numaAddNumber(nadelh, 0);
        } else {
            numaAddNumber(nadelw, bw - medw);
            numaAddNumber(nadelh, bh - medh);
        }
    }
    if (pnadelw)
        *pnadelw = nadelw;
    else
        numaDestroy(&nadelw);
    if (pnadelh)
        *pnadelh = nadelh;
    else
        numaDestroy(&nadelh);

    boxaDestroy(&boxae);
    boxaDestroy(&boxao);
    return 0;
}
/*!
 * \brief   boxaMedianDimensions()
 *
 * \param[in]    boxas    containing at least 3 valid boxes in even and odd
 * \param[out]   pmedw    [optional] median width of all boxes
 * \param[out]   pmedh    [optional] median height of all boxes
 * \param[out]   pmedwe   [optional] median width of even boxes
 * \param[out]   pmedwo   [optional] median width of odd boxes
 * \param[out]   pmedhe   [optional] median height of even boxes
 * \param[out]   pmedho   [optional] median height of odd boxes
 * \param[out]   pnadelw  [optional] width diff of each box from median
 * \param[out]   pnadelh  [optional] height diff of each box from median
 * \return  0 if OK, 1 on error
 *
 * <pre>
 * Notes:
 *      (1) This provides information that (1) allows identification of
 *          boxes that have unusual (outlier) width or height, and (2) can
 *          be used to regularize the sizes of the outlier boxes, assuming
 *          that the boxes satisfy a fairly regular sequence and should
 *          mostly have the same width and height.
 *      (2) This finds the median width and height, as well as separate
 *          median widths and heights of even and odd boxes.  It also
 *          generates arrays that give the difference in width and height
 *          of each box from the median, which can be used to correct
 *          individual boxes.
 *      (3) All return values are optional.
 * </pre>
 */



Notes:
(1) This provides information that (1) allows identification of
boxes that have unusual (outlier) width or height, and (2) can
be used to regularize the sizes of the outlier boxes, assuming
that the boxes satisfy a fairly regular sequence and should
mostly have the same width and height.
(2) This finds the median width and height, as well as separate
median widths and heights of even and odd boxes.  It also
generates arrays that give the difference in width and height
of each box from the median, which can be used to correct
individual boxes.
(3) All return values are optional.
Notes : ( 1 ) This provides information that ( 1 ) allows identification of boxes that have unusual ( outlier ) width or height and ( 2 ) can be used to regularize the sizes of the outlier boxes assuming that the boxes satisfy a fairly regular sequence and should mostly have the same width and height . ( 2 ) This finds the median width and height as well as separate median widths and heights of even and odd boxes . It also generates arrays that give the difference in width and height of each box from the median which can be used to correct individual boxes . ( 3 ) All return values are optional .
l_ok
boxaMedianDimensions(BOXA     *boxas,
                     l_int32  *pmedw,
                     l_int32  *pmedh,
                     l_int32  *pmedwe,
                     l_int32  *pmedwo,
                     l_int32  *pmedhe,
                     l_int32  *pmedho,
                     NUMA    **pnadelw,
                     NUMA    **pnadelh)
{
l_int32  i, n, bw, bh, medw, medh, medwe, medwo, medhe, medho;
BOXA    *boxae, *boxao;
NUMA    *nadelw, *nadelh;
    PROCNAME("boxaMedianDimensions");
    if (pmedw) *pmedw = 0;
    if (pmedh) *pmedh = 0;
    if (pmedwe) *pmedwe= 0;
    if (pmedwo) *pmedwo= 0;
    if (pmedhe) *pmedhe= 0;
    if (pmedho) *pmedho= 0;
    if (pnadelw) *pnadelw = NULL;
    if (pnadelh) *pnadelh = NULL;
    if (!boxas)
        return ERROR_INT("boxas not defined", procName, 1);
    if (boxaGetValidCount(boxas) < 6)
        return ERROR_INT("need at least 6 valid boxes", procName, 1);
    boxaSplitEvenOdd(boxas, 0, &boxae, &boxao);
    if (boxaGetValidCount(boxae) < 3 || boxaGetValidCount(boxao) < 3) {
        boxaDestroy(&boxae);
        boxaDestroy(&boxao);
        return ERROR_INT("don't have 3+ valid boxes of each type", procName, 1);
    }
    boxaGetMedianVals(boxas, NULL, NULL, NULL, NULL, &medw, &medh);
    boxaGetMedianVals(boxae, NULL, NULL, NULL, NULL, &medwe, &medhe);
    boxaGetMedianVals(boxao, NULL, NULL, NULL, NULL, &medwo, &medho);
    if (pmedw) *pmedw = medw;
    if (pmedh) *pmedh = medh;
    if (pmedwe) *pmedwe = medwe;
    if (pmedwo) *pmedwo = medwo;
    if (pmedhe) *pmedhe = medhe;
    if (pmedho) *pmedho = medho;
    n = boxaGetCount(boxas);
    nadelw = numaCreate(n);
    nadelh = numaCreate(n);
    for (i = 0; i < n; i++) {
        boxaGetBoxGeometry(boxas, i, NULL, NULL, &bw, &bh);
        if (bw == 0 || bh == 0) {  
            numaAddNumber(nadelw, 0);
            numaAddNumber(nadelh, 0);
        } else {
            numaAddNumber(nadelw, bw - medw);
            numaAddNumber(nadelh, bh - medh);
        }
    }
    if (pnadelw)
        *pnadelw = nadelw;
    else
        numaDestroy(&nadelw);
    if (pnadelh)
        *pnadelh = nadelh;
    else
        numaDestroy(&nadelh);
    boxaDestroy(&boxae);
    boxaDestroy(&boxao);
    return 0;
}
l_ok boxaMedianDimensions ( BOXA * boxas , l_int32 * pmedw , l_int32 * pmedh , l_int32 * pmedwe , l_int32 * pmedwo , l_int32 * pmedhe , l_int32 * pmedho , NUMA * * pnadelw , NUMA * * pnadelh ) { l_int32 i , n , bw , bh , medw , medh , medwe , medwo , medhe , medho ; BOXA * boxae , * boxao ; NUMA * nadelw , * nadelh ; PROCNAME ( " " ) ; if ( pmedw ) * pmedw = 0 ; if ( pmedh ) * pmedh = 0 ; if ( pmedwe ) * pmedwe = 0 ; if ( pmedwo ) * pmedwo = 0 ; if ( pmedhe ) * pmedhe = 0 ; if ( pmedho ) * pmedho = 0 ; if ( pnadelw ) * pnadelw = NULL ; if ( pnadelh ) * pnadelh = NULL ; if ( ! boxas ) return ERROR_INT ( " " , procName , 1 ) ; if ( boxaGetValidCount ( boxas ) < 6 ) return ERROR_INT ( " " , procName , 1 ) ; boxaSplitEvenOdd ( boxas , 0 , & boxae , & boxao ) ; if ( boxaGetValidCount ( boxae ) < 3 || boxaGetValidCount ( boxao ) < 3 ) { boxaDestroy ( & boxae ) ; boxaDestroy ( & boxao ) ; return ERROR_INT ( " " , procName , 1 ) ; } boxaGetMedianVals ( boxas , NULL , NULL , NULL , NULL , & medw , & medh ) ; boxaGetMedianVals ( boxae , NULL , NULL , NULL , NULL , & medwe , & medhe ) ; boxaGetMedianVals ( boxao , NULL , NULL , NULL , NULL , & medwo , & medho ) ; if ( pmedw ) * pmedw = medw ; if ( pmedh ) * pmedh = medh ; if ( pmedwe ) * pmedwe = medwe ; if ( pmedwo ) * pmedwo = medwo ; if ( pmedhe ) * pmedhe = medhe ; if ( pmedho ) * pmedho = medho ; n = boxaGetCount ( boxas ) ; nadelw = numaCreate ( n ) ; nadelh = numaCreate ( n ) ; for ( i = 0 ; i < n ; i ++ ) { boxaGetBoxGeometry ( boxas , i , NULL , NULL , & bw , & bh ) ; if ( bw == 0 || bh == 0 ) { numaAddNumber ( nadelw , 0 ) ; numaAddNumber ( nadelh , 0 ) ; } else { numaAddNumber ( nadelw , bw - medw ) ; numaAddNumber ( nadelh , bh - medh ) ; } } if ( pnadelw ) * pnadelw = nadelw ; else numaDestroy ( & nadelw ) ; if ( pnadelh ) * pnadelh = nadelh ; else numaDestroy ( & nadelh ) ; boxaDestroy ( & boxae ) ; boxaDestroy ( & boxao ) ; return 0 ; }
\brief   boxaMedianDimensions()
 \param[in]    boxas    containing at least 3 valid boxes in even and odd
 \param[out]   pmedw    [optional] median width of all boxes
 \param[out]   pmedh    [optional] median height of all boxes
 \param[out]   pmedwe   [optional] median width of even boxes
 \param[out]   pmedwo   [optional] median width of odd boxes
 \param[out]   pmedhe   [optional] median height of even boxes
 \param[out]   pmedho   [optional] median height of odd boxes
 \param[out]   pnadelw  [optional] width diff of each box from median
 \param[out]   pnadelh  [optional] height diff of each box from median
 \return  0 if OK, 1 on error
\ brief boxaMedianDimensions () \ param [ in ] boxas containing at least 3 valid boxes in even and odd \ param [ out ] pmedw [ optional ] median width of all boxes \ param [ out ] pmedh [ optional ] median height of all boxes \ param [ out ] pmedwe [ optional ] median width of even boxes \ param [ out ] pmedwo [ optional ] median width of odd boxes \ param [ out ] pmedhe [ optional ] median height of even boxes \ param [ out ] pmedho [ optional ] median height of odd boxes \ param [ out ] pnadelw [ optional ] width diff of each box from median \ param [ out ] pnadelh [ optional ] height diff of each box from median \ return 0 if OK 1 on error
/* Require at least 3 valid boxes of both types */ /* Get the relevant median widths and heights */ /* Find the variation from median dimension for each box */ /* invalid box */