src/jbclass.c
l_int32
pixHaustest(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  wi, hi, wt, ht, delw, delh, idelx, idely, boolmatch;
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;

        /* 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);
    pixZero(pixt, &boolmatch);
    if (boolmatch == 0) {
        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);
    pixZero(pixt, &boolmatch);
    pixDestroy(&pixt);
    return boolmatch;
}
/*!
 *  pixHaustest()
 *
 *      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)
 *      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.  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.
 *  These check that the dilated image of one contains
 *  ALL the pixels of the undilated image of the other.
 *  Checks are done in both direction.  A single pixel not
 *  contained 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.  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.
These check that the dilated image of one contains
ALL the pixels of the undilated image of the other.
Checks are done in both direction.  A single pixel not
contained 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 . 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 . These check that the dilated image of one contains ALL the pixels of the undilated image of the other . Checks are done in both direction . A single pixel not contained in either direction results in failure of the test .
l_int32
pixHaustest(PIX       *pix1,
            PIX       *pix2,
            PIX       *pix3,
            PIX       *pix4,
            l_float32  delx,   
            l_float32  dely,   
            l_int32    maxdiffw,
            l_int32    maxdiffh)
{
l_int32  wi, hi, wt, ht, delw, delh, idelx, idely, boolmatch;
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;
    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);
    pixZero(pixt, &boolmatch);
    if (boolmatch == 0) {
        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);
    pixZero(pixt, &boolmatch);
    pixDestroy(&pixt);
    return boolmatch;
}
l_int32 pixHaustest ( PIX * pix1 , PIX * pix2 , PIX * pix3 , PIX * pix4 , l_float32 delx , l_float32 dely , l_int32 maxdiffw , l_int32 maxdiffh ) { l_int32 wi , hi , wt , ht , delw , delh , idelx , idely , boolmatch ; 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 ; 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 ) ; pixZero ( pixt , & boolmatch ) ; if ( boolmatch == 0 ) { 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 ) ; pixZero ( pixt , & boolmatch ) ; pixDestroy ( & pixt ) ; return boolmatch ; }
pixHaustest()
      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)
      Return: 0 (FALSE) if no match, 1 (TRUE) if the new
              pix is in the same class as the exemplar.
pixHaustest () 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 ) 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 */ /* 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.  */ /*  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. */