src/finditalic.c
l_int32
pixItalicWords(PIX     *pixs,
               BOXA    *boxaw,
               PIX     *pixw,
               BOXA   **pboxa,
               l_int32  debugflag)
{
BOXA  *boxa;
PIX   *pixsd, *pixm, *pixd;
SEL   *sel_ital1, *sel_ital2, *sel_ital3;

    PROCNAME("pixItalicWords");

    if (!pixs)
        return ERROR_INT("pixs not defined", procName, 1);
    if (!pboxa)
        return ERROR_INT("&boxa not defined", procName, 1);
    if (boxaw && pixw)
        return ERROR_INT("both boxaw and pixw are defined", procName, 1);

    sel_ital1 = selCreateFromString(str_ital1, 13, 6, NULL);
    sel_ital2 = selCreateFromString(str_ital2, 10, 6, NULL);
    sel_ital3 = selCreateFromString(str_ital3, 4, 2, NULL);

	/* Make the italic seed: extract with HMT; remove noise */
    pixsd = pixHMT(NULL, pixs, sel_ital1);
    pixClose(pixsd, pixsd, sel_ital3);
    pixOpen(pixsd, pixsd, sel_ital3);

	/* Make the word mask.  Use input boxes or mask if given. */
    if (boxaw) {
        pixm = pixCreateTemplate(pixs);
        pixMaskBoxa(pixm, pixm, boxaw, L_SET_PIXELS);
    }
    else if (pixw) {
        pixm = pixClone(pixw);
    }
    else 
        pixm = pixMorphSequence(pixs, "d1.5 + c6.1", 0);

	/* Binary reconstruction */
    pixd = pixSeedfillBinary(NULL, pixsd, pixm, 8);
    boxa = pixConnComp(pixd, NULL, 8);
    *pboxa = boxa;

    if (debugflag) {
        BOXA  *boxat;
        PIXA  *pad;
        PIX   *pixt1, *pixt2;
        pad = pixaCreate(0);
        pixSaveTiledOutline(pixs, pad, 2, 1, 20, 2, 32);
        pixSaveTiledOutline(pixsd, pad, 2, 1, 20, 2, 0);
        boxat = pixConnComp(pixm, NULL, 8);
        boxaWrite("/tmp/junkboxa.ba", boxat);
        pixt1 = pixConvertTo32(pixm);
        pixRenderBoxaArb(pixt1, boxat, 3, 255, 0, 0);
        pixSaveTiledOutline(pixt1, pad, 2, 1, 20, 2, 0);
        pixDestroy(&pixt1);
        pixSaveTiledOutline(pixd, pad, 2, 1, 20, 2, 0);
        pixt1 = pixConvertTo32(pixs);
        pixRenderBoxaArb(pixt1, boxa, 3, 255, 0, 0);
        pixSaveTiledOutline(pixt1, pad, 2, 1, 20, 2, 0);
        pixt2 = pixaDisplay(pad, 0, 0);
        pixWrite("/tmp/junkdebug.png", pixt2, IFF_PNG);
        pixaDestroy(&pad);
        pixDestroy(&pixt1);
        pixDestroy(&pixt2);
        boxaDestroy(&boxat);
    }

    selDestroy(&sel_ital1);
    selDestroy(&sel_ital2);
    selDestroy(&sel_ital3);
    pixDestroy(&pixsd);
    pixDestroy(&pixm);
    pixDestroy(&pixd);
    return 0;
}
/*!
 *  pixItalicWords()
 *
 *      Input:  pixs (1 bpp)
 *              boxaw (<optional> word bounding boxes; can be NULL)
 *              pixw (<optional> word box mask; can be NULL)
 *              &boxa (<return> boxa of italian words) 
 *              debugflag (1 for debug output; 0 otherwise)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) You can input the bounding boxes for the words in one of
 *          two forms: as bounding boxes (@boxaw) or as a word mask with
 *          the word bounding boxes filled (@pixw).  For example,
 *          to compute @pixw, you can use pixWordMaskByDilation().
 *      (2) Alternatively, you can set both of these inputs to NULL,
 *          in which case the word mask is generated here.  This is
 *          done by dilating and closing the input image to connect
 *          letters within a word, while leaving the words separated.
 *          The parameters are chosen under the assumption that the
 *          input is 10 to 12 pt text, scanned at about 300 ppi.
 */
pixItalicWords()
Input:  pixs (1 bpp)
boxaw ( word bounding boxes; can be NULL)
pixw ( word box mask; can be NULL)
&boxa ( boxa of italian words)
debugflag (1 for debug output; 0 otherwise)
Return: 0 if OK, 1 on error

(1) You can input the bounding boxes for the words in one of
two forms: as bounding boxes (@boxaw) or as a word mask with
the word bounding boxes filled (@pixw).  For example,
to compute @pixw, you can use pixWordMaskByDilation().
(2) Alternatively, you can set both of these inputs to NULL,
in which case the word mask is generated here.  This is
done by dilating and closing the input image to connect
letters within a word, while leaving the words separated.
The parameters are chosen under the assumption that the
input is 10 to 12 pt text, scanned at about 300 ppi.
pixItalicWords () Input : pixs ( 1 bpp ) boxaw ( word bounding boxes ; can be NULL ) pixw ( word box mask ; can be NULL ) &boxa ( boxa of italian words ) debugflag ( 1 for debug output ; 0 otherwise ) Return : 0 if OK 1 on error ( 1 ) You can input the bounding boxes for the words in one of two forms : as bounding boxes ( @boxaw ) or as a word mask with the word bounding boxes filled ( @pixw ) . For example to compute @pixw you can use pixWordMaskByDilation () . ( 2 ) Alternatively you can set both of these inputs to NULL in which case the word mask is generated here . This is done by dilating and closing the input image to connect letters within a word while leaving the words separated . The parameters are chosen under the assumption that the input is 10 to 12 pt text scanned at about 300 ppi .
l_int32
pixItalicWords(PIX     *pixs,
               BOXA    *boxaw,
               PIX     *pixw,
               BOXA   **pboxa,
               l_int32  debugflag)
{
BOXA  *boxa;
PIX   *pixsd, *pixm, *pixd;
SEL   *sel_ital1, *sel_ital2, *sel_ital3;
    PROCNAME("pixItalicWords");
    if (!pixs)
        return ERROR_INT("pixs not defined", procName, 1);
    if (!pboxa)
        return ERROR_INT("&boxa not defined", procName, 1);
    if (boxaw && pixw)
        return ERROR_INT("both boxaw and pixw are defined", procName, 1);
    sel_ital1 = selCreateFromString(str_ital1, 13, 6, NULL);
    sel_ital2 = selCreateFromString(str_ital2, 10, 6, NULL);
    sel_ital3 = selCreateFromString(str_ital3, 4, 2, NULL);
    pixsd = pixHMT(NULL, pixs, sel_ital1);
    pixClose(pixsd, pixsd, sel_ital3);
    pixOpen(pixsd, pixsd, sel_ital3);
    if (boxaw) {
        pixm = pixCreateTemplate(pixs);
        pixMaskBoxa(pixm, pixm, boxaw, L_SET_PIXELS);
    }
    else if (pixw) {
        pixm = pixClone(pixw);
    }
    else 
        pixm = pixMorphSequence(pixs, "d1.5 + c6.1", 0);
    pixd = pixSeedfillBinary(NULL, pixsd, pixm, 8);
    boxa = pixConnComp(pixd, NULL, 8);
    *pboxa = boxa;
    if (debugflag) {
        BOXA  *boxat;
        PIXA  *pad;
        PIX   *pixt1, *pixt2;
        pad = pixaCreate(0);
        pixSaveTiledOutline(pixs, pad, 2, 1, 20, 2, 32);
        pixSaveTiledOutline(pixsd, pad, 2, 1, 20, 2, 0);
        boxat = pixConnComp(pixm, NULL, 8);
        boxaWrite("/tmp/junkboxa.ba", boxat);
        pixt1 = pixConvertTo32(pixm);
        pixRenderBoxaArb(pixt1, boxat, 3, 255, 0, 0);
        pixSaveTiledOutline(pixt1, pad, 2, 1, 20, 2, 0);
        pixDestroy(&pixt1);
        pixSaveTiledOutline(pixd, pad, 2, 1, 20, 2, 0);
        pixt1 = pixConvertTo32(pixs);
        pixRenderBoxaArb(pixt1, boxa, 3, 255, 0, 0);
        pixSaveTiledOutline(pixt1, pad, 2, 1, 20, 2, 0);
        pixt2 = pixaDisplay(pad, 0, 0);
        pixWrite("/tmp/junkdebug.png", pixt2, IFF_PNG);
        pixaDestroy(&pad);
        pixDestroy(&pixt1);
        pixDestroy(&pixt2);
        boxaDestroy(&boxat);
    }
    selDestroy(&sel_ital1);
    selDestroy(&sel_ital2);
    selDestroy(&sel_ital3);
    pixDestroy(&pixsd);
    pixDestroy(&pixm);
    pixDestroy(&pixd);
    return 0;
}
l_int32 pixItalicWords ( PIX * pixs , BOXA * boxaw , PIX * pixw , BOXA * * pboxa , l_int32 debugflag ) { BOXA * boxa ; PIX * pixsd , * pixm , * pixd ; SEL * sel_ital1 , * sel_ital2 , * sel_ital3 ; PROCNAME ( " " ) ; if ( ! pixs ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! pboxa ) return ERROR_INT ( " " , procName , 1 ) ; if ( boxaw && pixw ) return ERROR_INT ( " " , procName , 1 ) ; sel_ital1 = selCreateFromString ( str_ital1 , 13 , 6 , NULL ) ; sel_ital2 = selCreateFromString ( str_ital2 , 10 , 6 , NULL ) ; sel_ital3 = selCreateFromString ( str_ital3 , 4 , 2 , NULL ) ; pixsd = pixHMT ( NULL , pixs , sel_ital1 ) ; pixClose ( pixsd , pixsd , sel_ital3 ) ; pixOpen ( pixsd , pixsd , sel_ital3 ) ; if ( boxaw ) { pixm = pixCreateTemplate ( pixs ) ; pixMaskBoxa ( pixm , pixm , boxaw , L_SET_PIXELS ) ; } else if ( pixw ) { pixm = pixClone ( pixw ) ; } else pixm = pixMorphSequence ( pixs , " " , 0 ) ; pixd = pixSeedfillBinary ( NULL , pixsd , pixm , 8 ) ; boxa = pixConnComp ( pixd , NULL , 8 ) ; * pboxa = boxa ; if ( debugflag ) { BOXA * boxat ; PIXA * pad ; PIX * pixt1 , * pixt2 ; pad = pixaCreate ( 0 ) ; pixSaveTiledOutline ( pixs , pad , 2 , 1 , 20 , 2 , 32 ) ; pixSaveTiledOutline ( pixsd , pad , 2 , 1 , 20 , 2 , 0 ) ; boxat = pixConnComp ( pixm , NULL , 8 ) ; boxaWrite ( " " , boxat ) ; pixt1 = pixConvertTo32 ( pixm ) ; pixRenderBoxaArb ( pixt1 , boxat , 3 , 255 , 0 , 0 ) ; pixSaveTiledOutline ( pixt1 , pad , 2 , 1 , 20 , 2 , 0 ) ; pixDestroy ( & pixt1 ) ; pixSaveTiledOutline ( pixd , pad , 2 , 1 , 20 , 2 , 0 ) ; pixt1 = pixConvertTo32 ( pixs ) ; pixRenderBoxaArb ( pixt1 , boxa , 3 , 255 , 0 , 0 ) ; pixSaveTiledOutline ( pixt1 , pad , 2 , 1 , 20 , 2 , 0 ) ; pixt2 = pixaDisplay ( pad , 0 , 0 ) ; pixWrite ( " " , pixt2 , IFF_PNG ) ; pixaDestroy ( & pad ) ; pixDestroy ( & pixt1 ) ; pixDestroy ( & pixt2 ) ; boxaDestroy ( & boxat ) ; } selDestroy ( & sel_ital1 ) ; selDestroy ( & sel_ital2 ) ; selDestroy ( & sel_ital3 ) ; pixDestroy ( & pixsd ) ; pixDestroy ( & pixm ) ; pixDestroy ( & pixd ) ; return 0 ; }
pixItalicWords()
      Input:  pixs (1 bpp)
              boxaw (<optional> word bounding boxes; can be NULL)
              pixw (<optional> word box mask; can be NULL)
              &boxa (<return> boxa of italian words)
              debugflag (1 for debug output; 0 otherwise)
      Return: 0 if OK, 1 on error
pixItalicWords () Input : pixs ( 1 bpp ) boxaw ( <optional > word bounding boxes ; can be NULL ) pixw ( <optional > word box mask ; can be NULL ) &boxa ( <return > boxa of italian words ) debugflag ( 1 for debug output ; 0 otherwise ) Return : 0 if OK 1 on error
/* Make the italic seed: extract with HMT; remove noise */ /* Make the word mask.  Use input boxes or mask if given. */ /* Binary reconstruction */