42#include <config_auto.h>
45#include "allheaders.h"
50static const char *str_ital1 =
" o x"
64static const char *str_ital2 =
" o x"
78static const char *str_ital3 =
" x"
116pixItalicWords(
PIX *pixs,
122char opstring[32], buf[32];
125PIX *pixsd, *pixm, *pixd;
126SEL *sel_ital1, *sel_ital2, *sel_ital3;
129 return ERROR_INT(
"&boxa not defined", __func__, 1);
132 return ERROR_INT(
"pixs not defined", __func__, 1);
134 return ERROR_INT(
"both boxaw and pixw are defined", __func__, 1);
136 sel_ital1 = selCreateFromString(str_ital1, 13, 6, NULL);
137 sel_ital2 = selCreateFromString(str_ital2, 10, 6, NULL);
138 sel_ital3 = selCreateFromString(str_ital3, 4, 2, NULL);
144 pixsd = pixHMT(NULL, pixs, sel_ital1);
145 pixClose(pixsd, pixsd, sel_ital3);
146 pixOpen(pixsd, pixsd, sel_ital3);
151 pixm = pixCreateTemplate(pixs);
155 pixm = pixClone(pixw);
158 pixWordMaskByDilation(pixs, NULL, &size, NULL);
159 L_INFO(
"dilation size = %d\n", __func__, size);
160 snprintf(opstring,
sizeof(opstring),
"d1.5 + c%d.1", size);
161 pixm = pixMorphSequence(pixs, opstring, 0);
167 pixd = pixSeedfillBinary(NULL, pixsd, pixm, 8);
168 boxa = pixConnComp(pixd, NULL, 8);
174 lept_mkdir(
"lept/ital");
179 PIX *pix1, *pix2, *pix3;
180 pixa1 = pixaCreate(0);
181 boxat = pixConnComp(pixm, NULL, 8);
182 boxaWriteDebug(
"/tmp/lept/ital/ital.ba", boxat);
183 pixaAddPix(pixa1, pixs,
L_COPY);
184 pixaAddPix(pixa1, pixsd,
L_COPY);
185 pix1 = pixConvertTo32(pixm);
186 pixRenderBoxaArb(pix1, boxat, 3, 255, 0, 0);
188 pixaAddPix(pixa1, pixd,
L_COPY);
189 pix1 = pixConvertTo32(pixs);
190 pixRenderBoxaArb(pix1, boxa, 3, 255, 0, 0);
192 pix1 = pixCreateTemplate(pixs);
193 pix2 = pixSetBlackOrWhiteBoxa(pix1, boxa,
L_SET_BLACK);
195 pix3 = pixDilateBrick(NULL, pixs, 3, 3);
196 pixCombineMasked(pix1, pix3, pix2);
200 pix2 = pixaDisplayTiledInColumns(pixa1, 1, 0.5, 20, 2);
201 snprintf(buf,
sizeof(buf),
"/tmp/lept/ital/ital.%d.png", type);
202 pixWriteDebug(buf, pix2, IFF_PNG);
209 res = pixGetWidth(pixs) / 12;
210 L_INFO(
"resolution = %d\n", __func__, res);
211 l_pdfSetDateAndVersion(0);
212 snprintf(buf,
sizeof(buf),
"/tmp/lept/ital/ital.%d.pdf", type);
213 pixaConvertToPdf(pixa1, res, 1.0,
L_FLATE_ENCODE, 75,
"Italic Finder",
215 l_pdfSetDateAndVersion(1);
224 pix1 = pixDilateBrick(NULL, pixs, 1, 15);
225 upper = L_MAX(30, 3 * size);
226 na = pixRunHistogramMorph(pix1, L_RUN_OFF, L_HORIZ, upper);
228 gplot = gplotCreate(
"/tmp/lept/ital/runhisto", GPLOT_PNG,
229 "Histogram of horizontal runs of white pixels, vs length",
230 "run length",
"number of runs");
231 gplotAddPlot(gplot, NULL, na, GPLOT_LINES,
"plot1");
232 gplotMakeOutput(gplot);
233 gplotDestroy(&gplot);
237 selDestroy(&sel_ital1);
238 selDestroy(&sel_ital2);
239 selDestroy(&sel_ital3);