|
| static JBCLASSER * | jbCorrelationInitInternal (l_int32 components, l_int32 maxwidth, l_int32 maxheight, l_float32 thresh, l_float32 weightfactor, l_int32 keep_components) |
| |
| static JBFINDCTX * | findSimilarSizedTemplatesInit (JBCLASSER *classer, PIX *pixs) |
| |
| static l_int32 | findSimilarSizedTemplatesNext (JBFINDCTX *context) |
| |
| static void | findSimilarSizedTemplatesDestroy (JBFINDCTX **pcontext) |
| |
| static l_int32 | finalPositioningForAlignment (PIX *pixs, l_int32 x, l_int32 y, l_int32 idelx, l_int32 idely, PIX *pixt, l_int32 *sumtab, l_int32 *pdx, l_int32 *pdy) |
| |
| JBCLASSER * | jbRankHausInit (l_int32 components, l_int32 maxwidth, l_int32 maxheight, l_int32 size, l_float32 rank) |
| |
| JBCLASSER * | jbCorrelationInit (l_int32 components, l_int32 maxwidth, l_int32 maxheight, l_float32 thresh, l_float32 weightfactor) |
| |
| JBCLASSER * | jbCorrelationInitWithoutComponents (l_int32 components, l_int32 maxwidth, l_int32 maxheight, l_float32 thresh, l_float32 weightfactor) |
| |
| l_int32 | jbAddPages (JBCLASSER *classer, SARRAY *safiles) |
| |
| l_int32 | jbAddPage (JBCLASSER *classer, PIX *pixs) |
| |
| l_int32 | jbAddPageComponents (JBCLASSER *classer, PIX *pixs, BOXA *boxas, PIXA *pixas) |
| |
| l_int32 | jbClassifyRankHaus (JBCLASSER *classer, BOXA *boxa, PIXA *pixas) |
| |
| 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 | 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 | jbClassifyCorrelation (JBCLASSER *classer, BOXA *boxa, PIXA *pixas) |
| |
| l_int32 | jbGetComponents (PIX *pixs, l_int32 components, l_int32 maxwidth, l_int32 maxheight, BOXA **pboxad, PIXA **ppixad) |
| |
| l_int32 | pixWordMaskByDilation (PIX *pixs, l_int32 maxdil, PIX **ppixm, l_int32 *psize) |
| |
| l_int32 | pixWordBoxesByDilation (PIX *pixs, l_int32 maxdil, l_int32 minwidth, l_int32 minheight, l_int32 maxwidth, l_int32 maxheight, BOXA **pboxa, l_int32 *psize) |
| |
| PIXA * | jbAccumulateComposites (PIXAA *pixaa, NUMA **pna, PTA **pptat) |
| |
| PIXA * | jbTemplatesFromComposites (PIXA *pixac, NUMA *na) |
| |
| JBCLASSER * | jbClasserCreate (l_int32 method, l_int32 components) |
| |
| void | jbClasserDestroy (JBCLASSER **pclasser) |
| |
| JBDATA * | jbDataSave (JBCLASSER *classer) |
| |
| void | jbDataDestroy (JBDATA **pdata) |
| |
| l_int32 | jbDataWrite (const char *rootout, JBDATA *jbdata) |
| |
| JBDATA * | jbDataRead (const char *rootname) |
| |
| PIXA * | jbDataRender (JBDATA *data, l_int32 debugflag) |
| |
| l_int32 | jbGetULCorners (JBCLASSER *classer, PIX *pixs, BOXA *boxa) |
| |
| l_int32 | jbGetLLCorners (JBCLASSER *classer) |
| |
finalPositioningForAlignment()
Input: pixs (input page image)
x, y (location of UL corner of bb of component in pixs)
idelx, idely (compensation to match centroids of component
and template)
pixt (template, with JB_ADDED_PIXELS of padding on all sides)
sumtab (for summing fg pixels in an image)
&dx, &dy (return delta on position for best match; each
one is in the set {-1, 0, 1})
Return: 0 if OK, 1 on error
findSimilarSizedTemplatesNext()
Input: state (from findSimilarSizedTemplatesInit)
Return: next template number, or -1 when finished
We have a dna hash table that maps template area to a list of template numbers with that area. We wish to find similar sized templates, so we first look for templates with the same width and height, and then with width + 1, etc. This walk is guided by the two_by_two_walk array, above.
We don't want to have to collect the whole list of templates first, because we hope to find a well-matching template quickly. So we keep the context for this walk in an explictit state structure, and this function acts like a generator.
jbCorrelationInit()
Input: components (JB_CONN_COMPS, JB_CHARACTERS, JB_WORDS)
maxwidth (of component; use 0 for default)
maxheight (of component; use 0 for default)
thresh (value for correlation score: in [0.4 - 0.98])
weightfactor (corrects thresh for thick characters [0.0 - 1.0])
Return: jbclasser if OK; NULL on error
Notes: (1) For scanned text, suggested input values are: thresh ~ [0.8 - 0.85] weightfactor ~ [0.5 - 0.6] (2) For electronically generated fonts (e.g., rasterized pdf), a very high thresh (e.g., 0.95) will not cause a significant increase in the number of classes.
jbDataSave()
Input: jbclasser
latticew, latticeh (cell size used to store each
connected component in the composite)
Return: jbdata, or null on error
Notes: (1) This routine stores the jbig2-type data required for generating a lossy jbig2 version of the image. It can be losslessly written to (and read from) two files. (2) It generates and stores the mosaic of templates. (3) It clones the Numa and Pta arrays, so these must all be destroyed by the caller. (4) Input 0 to use the default values for latticew and/or latticeh,
jbGetLLCorners()
Input: jbclasser
Return: 0 if OK, 1 on error
Notes: (1) This computes the ptall field, which has the global LL corners, adjusted for each specific component, so that each component can be replaced by the template for its class and have the centroid in the template in the same position as the centroid of the original connected component. It is important that this be done properly to avoid a wavy baseline in the result. (2) It is computed here from the corresponding UL corners, where the input templates and stored instances are all bordered. This should be done after all pages have been processed. (3) For proper substitution, the templates whose LL corners are placed in these locations must be UN-bordered. This is available for a realistic jbig2 encoder, which would (1) encode each template without a border, and (2) encode the position using the LL corner (rather than the UL corner) because the difference between y-values of successive instances is typically close to zero.
jbGetULCorners()
Input: jbclasser
pixs (full res image)
boxa (of c.c. bounding rectangles for this page)
Return: 0 if OK, 1 on error
Notes: (1) This computes the ptaul field, which has the global UL corners, adjusted for each specific component, so that each component can be replaced by the template for its class and have the centroid in the template in the same position as the centroid of the original connected component. It is important that this be done properly to avoid a wavy baseline in the result. (2) The array fields ptac and ptact give the centroids of those components relative to the UL corner of each component. Here, we compute the difference in each component, round to nearest integer, and correct the box->x and box->y by the appropriate integral difference. (3) The templates and stored instances are all bordered.
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.
| 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 |
|
) |
| |
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.
pixWordMaskByDilation()
Input: pixs (1 bpp; typ. at 75 to 150 ppi)
maxdil (maximum dilation; 0 for default; warning if > 20)
&mask (<optional return> dilated word mask)
&size (<optional return> size of optimal horiz Sel)
Return: 0 if OK, 1 on error
Notes: (1) This gives a crude estimate of the word masks. See pixWordBoxesByDilation() for further filtering of the word boxes. (2) For 75 to 150 ppi, the optimal dilation will be between 5 and 11. For 200 to 300 ppi, it is advisable to use a larger value for @maxdil, say between 10 and 20. Setting maxdil <= 0 results in a default dilation of 16. (3) The best size for dilating to get word masks is optionally returned.