src/jbclass.c
l_int32
pixRankHaustest(PIX       *pix1,
                PIX       *pix2,
                PIX       *pix3,
                PIX       *pix4,
                l_float32  delx,   /* x(1) - x(3) */
                l_float32  dely,   /* y(1) - y(3) */
                l_int32    maxdiffw,
                l_int32    maxdiffh,
                l_int32    area1,
                l_int32    area3,
                l_float32  rank,
                l_int32   *tab8)
{
l_int32  wi, hi, wt, ht, delw, delh, idelx, idely, boolmatch;
l_int32  thresh1, thresh3;
PIX     *pixt;

        /* Eliminate possible matches based on size difference */
    wi = pixGetWidth(pix1);
    hi = pixGetHeight(pix1);
    wt = pixGetWidth(pix3);
    ht = pixGetHeight(pix3);
    delw = L_ABS(wi - wt);
    if (delw > maxdiffw)
        return FALSE;
    delh = L_ABS(hi - ht);
    if (delh > maxdiffh)
        return FALSE;

        /* Upper bounds in remaining pixels for allowable match */
    thresh1 = (l_int32)(area1 * (1. - rank) + 0.5);
    thresh3 = (l_int32)(area3 * (1. - rank) + 0.5);

        /* Round difference in centroid location to nearest integer;
         * use this as a shift when doing the matching. */
    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);

        /*  Do 1-direction hausdorff, checking that every pixel in pix1
         *  is within a dilation distance of some pixel in pix3.  Namely,
         *  that pix4 entirely covers pix1:
         *       pixt = pixSubtract(NULL, pix1, pix4), including shift
         *  where pixt has no ON pixels.  */
    pixt = pixCreateTemplate(pix1);
    pixRasterop(pixt, 0, 0, wi, hi, PIX_SRC, pix1, 0, 0);
    pixRasterop(pixt, idelx, idely, wi, hi, PIX_DST & PIX_NOT(PIX_SRC),
                pix4, 0, 0);
    pixThresholdPixelSum(pixt, thresh1, &boolmatch, tab8);
    if (boolmatch == 1) { /* above thresh1 */
        pixDestroy(&pixt);
        return FALSE;
    }

        /*  Do 1-direction hausdorff, checking that every pixel in pix3
         *  is within a dilation distance of some pixel in pix1.  Namely,
         *  that pix2 entirely covers pix3:
         *      pixSubtract(pixt, pix3, pix2), including shift
         *  where pixt has no ON pixels. */
    pixRasterop(pixt, idelx, idely, wt, ht, PIX_SRC, pix3, 0, 0);
    pixRasterop(pixt, 0, 0, wt, ht, PIX_DST & PIX_NOT(PIX_SRC), pix2, 0, 0);
    pixThresholdPixelSum(pixt, thresh3, &boolmatch, tab8);
    pixDestroy(&pixt);
    if (boolmatch == 1)  /* above thresh3 */
        return FALSE;
    else
        return TRUE;
}
/*!
 *  pixRankHaustest()
 *
 *      Input:  pix1   (new pix, not dilated)
 *              pix2   (new pix, dilated)
 *              pix3   (exemplar pix, not dilated)
 *              pix4   (exemplar pix, dilated)
 *              delx   (x comp of centroid difference)
 *              dely   (y comp of centroid difference)
 *              maxdiffw (max width difference of pix1 and pix2)
 *              maxdiffh (max height difference of pix1 and pix2)
 *              area1  (fg pixels in pix1)
 *              area3  (fg pixels in pix3)
 *              rank   (rank value of test, each way)
 *              tab8   (table of pixel sums for byte)
 *      Return: 0 (FALSE) if no match, 1 (TRUE) if the new
 *                 pix is in the same class as the exemplar.
 *
 *  Note: we check first that the two pix are roughly
 *  the same size.  Only if they meet that criterion do
 *  we compare the bitmaps.  We convert the rank value to
 *  a number of pixels by multiplying the rank fraction by the number
 *  of pixels in the undilated image.  The Hausdorff is a 2-way
 *  check.  The centroid difference is used to align the two
 *  images to the nearest integer for each of the checks.
 *  The rank hausdorff checks that the dilated image of one
 *  contains the rank fraction of the pixels of the undilated
 *  image of the other.   Checks are done in both direction. 
 *  Failure of the test in either direction results in failure
 *  of the test.
 */


we check first that the two pix are roughly
the same size.  Only if they meet that criterion do
we compare the bitmaps.  We convert the rank value to
a number of pixels by multiplying the rank fraction by the number
of pixels in the undilated image.  The Hausdorff is a 2-way
check.  The centroid difference is used to align the two
images to the nearest integer for each of the checks.
The rank hausdorff checks that the dilated image of one
contains the rank fraction of the pixels of the undilated
image of the other.   Checks are done in both direction.
Failure of the test in either direction results in failure
of the test.
we check first that the two pix are roughly the same size . Only if they meet that criterion do we compare the bitmaps . We convert the rank value to a number of pixels by multiplying the rank fraction by the number of pixels in the undilated image . The Hausdorff is a 2 - way check . The centroid difference is used to align the two images to the nearest integer for each of the checks . The rank hausdorff checks that the dilated image of one contains the rank fraction of the pixels of the undilated image of the other . Checks are done in both direction . Failure of the test in either direction results in failure of the test .
l_int32
pixRankHaustest(PIX       *pix1,
                PIX       *pix2,
                PIX       *pix3,
                PIX       *pix4,
                l_float32  delx,   
                l_float32  dely,   
                l_int32    maxdiffw,
                l_int32    maxdiffh,
                l_int32    area1,
                l_int32    area3,
                l_float32  rank,
                l_int32   *tab8)
{
l_int32  wi, hi, wt, ht, delw, delh, idelx, idely, boolmatch;
l_int32  thresh1, thresh3;
PIX     *pixt;
    wi = pixGetWidth(pix1);
    hi = pixGetHeight(pix1);
    wt = pixGetWidth(pix3);
    ht = pixGetHeight(pix3);
    delw = L_ABS(wi - wt);
    if (delw > maxdiffw)
        return FALSE;
    delh = L_ABS(hi - ht);
    if (delh > maxdiffh)
        return FALSE;
    thresh1 = (l_int32)(area1 * (1. - rank) + 0.5);
    thresh3 = (l_int32)(area3 * (1. - rank) + 0.5);
    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);
    pixt = pixCreateTemplate(pix1);
    pixRasterop(pixt, 0, 0, wi, hi, PIX_SRC, pix1, 0, 0);
    pixRasterop(pixt, idelx, idely, wi, hi, PIX_DST & PIX_NOT(PIX_SRC),
                pix4, 0, 0);
    pixThresholdPixelSum(pixt, thresh1, &boolmatch, tab8);
    if (boolmatch == 1) { 
        pixDestroy(&pixt);
        return FALSE;
    }
    pixRasterop(pixt, idelx, idely, wt, ht, PIX_SRC, pix3, 0, 0);
    pixRasterop(pixt, 0, 0, wt, ht, PIX_DST & PIX_NOT(PIX_SRC), pix2, 0, 0);
    pixThresholdPixelSum(pixt, thresh3, &boolmatch, tab8);
    pixDestroy(&pixt);
    if (boolmatch == 1)  
        return FALSE;
    else
        return TRUE;
}
l_int32 pixRankHaustest ( PIX * pix1 , PIX * pix2 , PIX * pix3 , PIX * pix4 , l_float32 delx , l_float32 dely , l_int32 maxdiffw , l_int32 maxdiffh , l_int32 area1 , l_int32 area3 , l_float32 rank , l_int32 * tab8 ) { l_int32 wi , hi , wt , ht , delw , delh , idelx , idely , boolmatch ; l_int32 thresh1 , thresh3 ; PIX * pixt ; wi = pixGetWidth ( pix1 ) ; hi = pixGetHeight ( pix1 ) ; wt = pixGetWidth ( pix3 ) ; ht = pixGetHeight ( pix3 ) ; delw = L_ABS ( wi - wt ) ; if ( delw > maxdiffw ) return FALSE ; delh = L_ABS ( hi - ht ) ; if ( delh > maxdiffh ) return FALSE ; thresh1 = ( l_int32 ) ( area1 * ( 1. - rank ) + 0.5 ) ; thresh3 = ( l_int32 ) ( area3 * ( 1. - rank ) + 0.5 ) ; 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 ) ; pixt = pixCreateTemplate ( pix1 ) ; pixRasterop ( pixt , 0 , 0 , wi , hi , PIX_SRC , pix1 , 0 , 0 ) ; pixRasterop ( pixt , idelx , idely , wi , hi , PIX_DST & PIX_NOT ( PIX_SRC ) , pix4 , 0 , 0 ) ; pixThresholdPixelSum ( pixt , thresh1 , & boolmatch , tab8 ) ; if ( boolmatch == 1 ) { pixDestroy ( & pixt ) ; return FALSE ; } pixRasterop ( pixt , idelx , idely , wt , ht , PIX_SRC , pix3 , 0 , 0 ) ; pixRasterop ( pixt , 0 , 0 , wt , ht , PIX_DST & PIX_NOT ( PIX_SRC ) , pix2 , 0 , 0 ) ; pixThresholdPixelSum ( pixt , thresh3 , & boolmatch , tab8 ) ; pixDestroy ( & pixt ) ; if ( boolmatch == 1 ) return FALSE ; else return TRUE ; }
pixRankHaustest()
      Input:  pix1   (new pix, not dilated)
              pix2   (new pix, dilated)
              pix3   (exemplar pix, not dilated)
              pix4   (exemplar pix, dilated)
              delx   (x comp of centroid difference)
              dely   (y comp of centroid difference)
              maxdiffw (max width difference of pix1 and pix2)
              maxdiffh (max height difference of pix1 and pix2)
              area1  (fg pixels in pix1)
              area3  (fg pixels in pix3)
              rank   (rank value of test, each way)
              tab8   (table of pixel sums for byte)
      Return: 0 (FALSE) if no match, 1 (TRUE) if the new
                 pix is in the same class as the exemplar.
pixRankHaustest () Input : pix1 ( new pix not dilated ) pix2 ( new pix dilated ) pix3 ( exemplar pix not dilated ) pix4 ( exemplar pix dilated ) delx ( x comp of centroid difference ) dely ( y comp of centroid difference ) maxdiffw ( max width difference of pix1 and pix2 ) maxdiffh ( max height difference of pix1 and pix2 ) area1 ( fg pixels in pix1 ) area3 ( fg pixels in pix3 ) rank ( rank value of test each way ) tab8 ( table of pixel sums for byte ) Return : 0 ( FALSE ) if no match 1 ( TRUE ) if the new pix is in the same class as the exemplar .
/* x(1) - x(3) */ /* y(1) - y(3) */ /* Eliminate possible matches based on size difference */ /* Upper bounds in remaining pixels for allowable match */ /* Round difference in centroid location to nearest integer;
         * use this as a shift when doing the matching. */ /*  Do 1-direction hausdorff, checking that every pixel in pix1
         *  is within a dilation distance of some pixel in pix3.  Namely,
         *  that pix4 entirely covers pix1:
         *       pixt = pixSubtract(NULL, pix1, pix4), including shift
         *  where pixt has no ON pixels.  */ /* above thresh1 */ /*  Do 1-direction hausdorff, checking that every pixel in pix3
         *  is within a dilation distance of some pixel in pix1.  Namely,
         *  that pix2 entirely covers pix3:
         *      pixSubtract(pixt, pix3, pix2), including shift
         *  where pixt has no ON pixels. */ /* above thresh3 */