Leptonica 1.68
C Image Processing Library
|
data extraction from a set of pages for jbig2 compression More...
Go to the source code of this file.
data extraction from a set of pages for jbig2 compression
These are functions for unsupervised classification of collections of connected components -- either characters or words -- in binary images. They can be used as image processing steps in jbig2 compression. Initialization JBCLASSER *jbRankHausInit() [rank hausdorff encoder] JBCLASSER *jbCorrelationInit() [correlation encoder] JBCLASSER *jbCorrelationInitWithoutComponents() [ditto] static JBCLASSER *jbCorrelationInitInternal() Classify the pages l_int32 jbAddPages() l_int32 jbAddPage() l_int32 jbAddPageComponents() Rank hausdorff classifier l_int32 jbClassifyRankHaus() l_int32 pixHaustest() l_int32 pixRankHaustest() Binary correlation classifier l_int32 jbClassifyCorrelation() Determine the image components we start with l_int32 jbGetComponents() PIX *pixWordMaskByDilation() Build grayscale composites (templates) PIXA *jbAccumulateComposites PIXA *jbTemplatesFromComposites Utility functions for Classer JBCLASSER *jbClasserCreate() void jbClasserDestroy() Utility functions for Data JBDATA *jbDataSave() void jbDataDestroy() l_int32 jbDataWrite() JBDATA *jbDataRead() PIXA *jbDataRender() l_int32 jbGetULCorners() l_int32 jbGetLLCorners() Static helpers static JBFINDCTX *findSimilarSizedTemplatesInit() static l_int32 findSimilarSizedTemplatesNext() static void findSimilarSizedTemplatesDestroy() static l_int32 finalPositioningForAlignment() Note: this is NOT an implementation of the JPEG jbig2 proposed standard encoder, the specifications for which can be found at http://www.jpeg.org/jbigpt2.html. (See below for a full implementation.) It is an implementation of the lower-level part of an encoder that: (1) identifies connected components that are going to be used (2) puts them in similarity classes (this is an unsupervised classifier), and (3) stores the result in a simple file format (2 files, one for templates and one for page/coordinate/template-index quartets). An actual implementation of the official jbig2 encoder could start with parts (1) and (2), and would then compress the quartets according to the standards requirements (e.g., Huffman or arithmetic coding of coordinate differences and image templates). The low-level part of the encoder provided here has the following useful features: - It is accurate in the identification of templates and classes because it uses a windowed hausdorff distance metric. - It is accurate in the placement of the connected components, doing a two step process of first aligning the the centroids of the template with those of each instance, and then making a further correction of up to +- 1 pixel in each direction to best align the templates. - It is fast because it uses a morphologically based matching algorithm to implement the hausdorff criterion, and it selects the patterns that are possible matches based on their size. We provide two different matching functions, one using Hausdorff distance and one using a simple image correlation. The Hausdorff method sometimes produces better results for the same number of classes, because it gives a relatively small effective weight to foreground pixels near the boundary, and a relatively large weight to foreground pixels that are not near the boundary. By effectively ignoring these boundary pixels, Hausdorff weighting corresponds better to the expected probabilities of the pixel values in a scanned image, where the variations in instances of the same printed character are much more likely to be in pixels near the boundary. By contrast, the correlation method gives equal weight to all foreground pixels. For best results, use the correlation method. Correlation takes the number of fg pixels in the AND of instance and template, divided by the product of the number of fg pixels in instance and template. It compares this with a threshold that, in general, depends on the fractional coverage of the template. For heavy text, the threshold is raised above that for light text, By using both these parameters (basic threshold and adjustment factor for text weight), one has more flexibility and can arrive at the fewest substitution errors, although this comes at the price of more templates. The strict Hausdorff scoring is not a rank weighting, because a single pixel beyond the given distance will cause a match failure. A rank Hausdorff is more robust to non-boundary noise, but it is also more susceptible to confusing components that should be in different classes. For implementing a jbig2 application for visually lossless binary image compression, you have two choices: (1) use a 3x3 structuring element (size = 3) and a strict Hausdorff comparison (rank = 1.0 in the rank Hausdorff function). This will result in a minimal number of classes, but confusion of small characters, such as italic and non-italic lower-case 'o', can still occur. (2) use the correlation method with a threshold of 0.85 and a weighting factor of about 0.7. This will result in a larger number of classes, but should not be confused either by similar small characters or by extremely thick sans serif characters, such as in prog/cootoots.png. As mentioned above, if visual substitution errors must be avoided, you should use the correlation method. We provide executables that show how to do the encoding: prog/jbrankhaus.c prog/jbcorrelation.c The basic flow for correlation classification goes as follows, where specific choices have been made for parameters (Hausdorff is the same except for initialization): // Initialize and save data in the classer JBCLASSER *classer = jbCorrelationInit(JB_CONN_COMPS, 0, 0, 0.8, 0.7); SARRAY *safiles = getSortedPathnamesInDirectory(directory, NULL, 0, 0); jbAddPages(classer, safiles); // Save the data in a data structure for serialization, // and write it into two files. JBDATA *data = jbDataSave(classer); jbDataWrite(rootname, data); // Reconstruct (render) the pages from the encoded data. PIXA *pixa = jbDataRender(data, FALSE); Adam Langley has recently built a jbig2 standards-compliant encoder, the first one to appear in open source. You can get this encoder at: http://www.imperialviolet.org/jbig2.html It uses arithmetic encoding throughout. It encodes binary images losslessly with a single arithmetic coding over the full image. It also does both lossy and lossless encoding from connected components, using leptonica to generate the templates representing each cluster.
Definition in file jbclass.c.
#define L_BUF_SIZE 512 |
Definition at line 201 of file jbclass.c.
Referenced by jbDataRead(), and jbDataWrite().
#define MAX_ALLOWED_DILATION 14 |
Definition at line 227 of file jbclass.c.
Referenced by pixWordMaskByDilation().
typedef struct JbFindTemplatesState JBFINDCTX |
static JBCLASSER * jbCorrelationInitInternal | ( | l_int32 | components, |
l_int32 | maxwidth, | ||
l_int32 | maxheight, | ||
l_float32 | thresh, | ||
l_float32 | weightfactor, | ||
l_int32 | keep_components | ||
) | [static] |
Definition at line 370 of file jbclass.c.
References JbFindTemplatesState::classer, ERROR_PTR, JB_CHARACTERS, JB_CONN_COMPS, JB_CORRELATION, JB_WORDS, jbClasserCreate(), JbClasser::keep_pixaa, MAX_CHAR_COMP_WIDTH, MAX_COMP_HEIGHT, MAX_CONN_COMP_WIDTH, MAX_WORD_COMP_WIDTH, JbClasser::maxheight, JbClasser::maxwidth, JbClasser::nahash, NULL, numaHashCreate(), PROCNAME, JbClasser::thresh, and JbClasser::weightfactor.
Referenced by jbCorrelationInit(), and jbCorrelationInitWithoutComponents().
findSimilarSizedTemplatesInit()
Input: classer pixs (instance to be matched) Return: Allocated context to be used with findSimilar*
Definition at line 2246 of file jbclass.c.
References CALLOC, JbFindTemplatesState::classer, JbFindTemplatesState::h, JB_ADDED_PIXELS, pixGetHeight(), pixGetWidth(), and JbFindTemplatesState::w.
Referenced by jbClassifyCorrelation(), and jbClassifyRankHaus().
findSimilarSizedTemplatesNext()
Input: state (from findSimilarSizedTemplatesInit) Return: Next template number, or -1 when finished
We have a hash table mapping 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 it quickly. So we keep the context for this walk in an explictit state structure and this function acts like a generator.
Definition at line 2298 of file jbclass.c.
References Numa::array, JbFindTemplatesState::classer, JbFindTemplatesState::h, JbFindTemplatesState::i, JB_ADDED_PIXELS, L_CLONE, JbFindTemplatesState::n, JbClasser::nahash, JbFindTemplatesState::numa, numaDestroy(), numaGetCount(), numaHashGetNuma(), pixaGetPix(), JbClasser::pixat, pixDestroy(), pixGetHeight(), pixGetWidth(), size, two_by_two_walk, and JbFindTemplatesState::w.
Referenced by jbClassifyCorrelation(), and jbClassifyRankHaus().
static void findSimilarSizedTemplatesDestroy | ( | JBFINDCTX ** | pcontext | ) | [static] |
Definition at line 2261 of file jbclass.c.
References FREE, L_WARNING, NULL, JbFindTemplatesState::numa, numaDestroy(), and PROCNAME.
Referenced by jbClassifyCorrelation(), and jbClassifyRankHaus().
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 | ||
) | [static] |
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
Definition at line 2363 of file jbclass.c.
References boxCreate(), boxDestroy(), ERROR_INT, JbFindTemplatesState::h, JbFindTemplatesState::i, JB_ADDED_PIXELS, NULL, PIX_DST, PIX_SRC, pixClipRectangle(), pixCopy(), pixCountPixels(), pixCreate(), pixDestroy(), pixGetHeight(), pixGetWidth(), pixRasterop(), PROCNAME, and JbFindTemplatesState::w.
Referenced by jbGetULCorners().
JBCLASSER* jbRankHausInit | ( | l_int32 | components, |
l_int32 | maxwidth, | ||
l_int32 | maxheight, | ||
l_int32 | size, | ||
l_float32 | rank | ||
) |
Input: components (JB_CONN_COMPS, JB_CHARACTERS, JB_WORDS) maxwidth (of component; use 0 for default) maxheight (of component; use 0 for default) size (of square structuring element; 2, representing 2x2 sel, is necessary for reasonable accuracy of small components; combine this with rank ~ 0.97 to avoid undue class expansion) rank (rank val of match, each way; in [0.5 - 1.0]; when using size = 2, 0.97 is a reasonable value) Return: jbclasser if OK; NULL on error
Definition at line 280 of file jbclass.c.
References JbFindTemplatesState::classer, ERROR_PTR, JB_CHARACTERS, JB_CONN_COMPS, JB_RANKHAUS, JB_WORDS, jbClasserCreate(), MAX_CHAR_COMP_WIDTH, MAX_COMP_HEIGHT, MAX_CONN_COMP_WIDTH, MAX_WORD_COMP_WIDTH, JbClasser::maxheight, JbClasser::maxwidth, JbClasser::nahash, NULL, numaHashCreate(), PROCNAME, JbClasser::rankhaus, size, and JbClasser::sizehaus.
Referenced by jbRankHaus(), and main().
JBCLASSER* jbCorrelationInit | ( | l_int32 | components, |
l_int32 | maxwidth, | ||
l_int32 | maxheight, | ||
l_float32 | thresh, | ||
l_float32 | weightfactor | ||
) |
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.
Definition at line 338 of file jbclass.c.
References jbCorrelationInitInternal().
Referenced by jbCorrelation(), jbWordsInTextlines(), and main().
JBCLASSER* jbCorrelationInitWithoutComponents | ( | l_int32 | components, |
l_int32 | maxwidth, | ||
l_int32 | maxheight, | ||
l_float32 | thresh, | ||
l_float32 | weightfactor | ||
) |
jbCorrelationInitWithoutComponents()
Input: same as jbCorrelationInit Output: same as jbCorrelationInit
Note: acts the same as jbCorrelationInit(), but the resulting object doesn't keep a list of all the components.
Definition at line 358 of file jbclass.c.
References jbCorrelationInitInternal().
Input: jbclasser safiles (of page image file names) Return: 0 if OK; 1 on error
Note: (1) jbclasser makes a copy of the array of file names. (2) The caller is still responsible for destroying the input array.
Definition at line 429 of file jbclass.c.
References ERROR_INT, JbFindTemplatesState::i, jbAddPage(), L_WARNING_INT, nfiles, NULL, pixDestroy(), pixGetDepth(), pixRead(), PROCNAME, JbClasser::safiles, sarrayCopy(), sarrayGetCount(), and sarrayGetString().
Referenced by jbCorrelation(), jbRankHaus(), and main().
Input: jbclasser pixs (of input page) Return: 0 if OK; 1 on error
Definition at line 471 of file jbclass.c.
References boxaDestroy(), JbClasser::components, ERROR_INT, JbClasser::h, jbAddPageComponents(), jbGetComponents(), JbClasser::maxheight, JbClasser::maxwidth, pixaDestroy(), pixGetDepth(), pixGetHeight(), pixGetWidth(), PROCNAME, and JbClasser::w.
Referenced by jbAddPages().
Input: jbclasser pixs (of input page) boxas (b.b. of components for this page) pixas (components for this page) Return: 0 if OK; 1 on error
Notes: (1) If there are no components on the page, we don't require input of empty boxas or pixas, although that's the typical situation.
Definition at line 514 of file jbclass.c.
References JbClasser::baseindex, boxaGetCount(), ERROR_INT, JB_RANKHAUS, jbClassifyCorrelation(), jbClassifyRankHaus(), jbGetULCorners(), JbClasser::method, JbFindTemplatesState::n, JbClasser::nacomps, JbClasser::npages, numaAddNumber(), and PROCNAME.
Referenced by jbAddPage(), and jbWordsInTextlines().
Input: jbclasser boxa (of new components for classification) pixas (of new components for classification) Return: 0 if OK; 1 on error
Definition at line 576 of file jbclass.c.
References boxaGetBox(), ERROR_INT, FALSE, findSimilarSizedTemplatesDestroy(), findSimilarSizedTemplatesInit(), findSimilarSizedTemplatesNext(), FREE, JbFindTemplatesState::i, JB_ADDED_PIXELS, JbClasser::keep_pixaa, L_CLONE, L_INSERT, makePixelSumTab8(), MAX_DIFF_HEIGHT, MAX_DIFF_WIDTH, JbFindTemplatesState::n, JbClasser::naclass, JbClasser::nafgt, JbClasser::nahash, JbClasser::napage, JbClasser::nclass, JbClasser::npages, NULL, numaAddNumber(), numaDestroy(), numaGetIValue(), numaHashAdd(), JbClasser::pixaa, pixaaAddPixa(), pixaAddBox(), pixaAddPix(), pixaaGetPixa(), pixaCentroids(), pixaCountPixels(), pixaCreate(), pixAddBorderGeneral(), pixaDestroy(), pixaGetCount(), pixaGetPix(), JbClasser::pixat, JbClasser::pixatd, pixDestroy(), pixDilate(), pixGetHeight(), pixGetWidth(), pixHaustest(), pixRankHaustest(), PROCNAME, ptaAddPt(), JbClasser::ptac, JbClasser::ptact, ptaDestroy(), ptaGetPt(), ptaJoin(), JbClasser::rankhaus, SEL_HIT, selCreateBrick(), selDestroy(), size, JbClasser::sizehaus, TRUE, x1, x2, y1, and y2.
Referenced by jbAddPageComponents().
l_int32 pixHaustest | ( | PIX * | pix1, |
PIX * | pix2, | ||
PIX * | pix3, | ||
PIX * | pix4, | ||
l_float32 | delx, | ||
l_float32 | dely, | ||
l_int32 | maxdiffw, | ||
l_int32 | maxdiffh | ||
) |
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.
Definition at line 833 of file jbclass.c.
References FALSE, L_ABS, PIX_DST, PIX_NOT, PIX_SRC, pixCreateTemplate(), pixDestroy(), pixGetHeight(), pixGetWidth(), pixRasterop(), and pixZero().
Referenced by jbClassifyRankHaus().
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 | ||
) |
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.
Definition at line 928 of file jbclass.c.
References FALSE, L_ABS, PIX_DST, PIX_NOT, PIX_SRC, pixCreateTemplate(), pixDestroy(), pixGetHeight(), pixGetWidth(), pixRasterop(), pixThresholdPixelSum(), and TRUE.
Referenced by jbClassifyRankHaus().
Input: jbclasser boxa (of new components for classification) pixas (of new components for classification) Return: 0 if OK; 1 on error
Definition at line 1015 of file jbclass.c.
References boxaGetBox(), CALLOC, ERROR_INT, FALSE, findSimilarSizedTemplatesDestroy(), findSimilarSizedTemplatesInit(), findSimilarSizedTemplatesNext(), FREE, JbFindTemplatesState::i, JB_ADDED_PIXELS, JbClasser::keep_pixaa, L_CLONE, L_INSERT, makePixelCentroidTab8(), makePixelSumTab8(), MAX_DIFF_HEIGHT, MAX_DIFF_WIDTH, JbFindTemplatesState::n, JbClasser::naarea, JbClasser::naclass, JbClasser::nafgt, JbClasser::nahash, JbClasser::napage, JbClasser::nclass, JbClasser::npages, numaAddNumber(), numaGetIValue(), numaHashAdd(), JbClasser::pixaa, pixaaAddPixa(), pixaAddBox(), pixaAddPix(), pixaaGetPixa(), pixaCreate(), pixAddBorderGeneral(), pixaDestroy(), pixaGetCount(), pixaGetPix(), JbClasser::pixat, pixCorrelationScore(), pixCorrelationScoreSimple(), pixCorrelationScoreThresholded(), pixDestroy(), pixGetData(), pixGetHeight(), pixGetWidth(), pixGetWpl(), PROCNAME, ptaAddPt(), JbClasser::ptac, ptaCreate(), JbClasser::ptact, ptaDestroy(), ptaGetPt(), ptaJoin(), JbClasser::thresh, TRUE, JbClasser::weightfactor, x1, x2, y1, and y2.
Referenced by jbAddPageComponents().
l_int32 jbGetComponents | ( | PIX * | pixs, |
l_int32 | components, | ||
l_int32 | maxwidth, | ||
l_int32 | maxheight, | ||
BOXA ** | pboxad, | ||
PIXA ** | ppixad | ||
) |
Input: pixs (1 bpp) components (JB_CONN_COMPS, JB_CHARACTERS, JB_WORDS) maxwidth, maxheight (of saved components; larger are discarded) &pboxa (<return> b.b. of component items) &ppixa (<return> component items) Return: 0 if OK, 1 on error
Definition at line 1292 of file jbclass.c.
References boxaCreate(), boxaDestroy(), boxaSelectBySize(), ERROR_INT, JB_CHARACTERS, JB_CONN_COMPS, JB_WORDS, L_SELECT_IF_BOTH, L_SELECT_IF_LTE, NULL, pixaClipToPix(), pixaCreate(), pixaDestroy(), pixaSelectBySize(), pixClone(), pixConnComp(), pixDestroy(), pixExpandReplicate(), pixGetXRes(), pixMorphSequence(), pixReduceRankBinaryCascade(), pixWordMaskByDilation(), pixZero(), and PROCNAME.
Referenced by jbAddPage().
Input: pixs (1 bpp; typ. at 75 to 150 ppi) maxsize (use 0 for default; not to exceed 14) &size (<optional return>=""> size of optimal horiz Sel) Return: pixd (dilated word mask), or null on error
Notes: (1) For 75 to 150 ppi, the optimal dilation should not exceed 7. This is the default size chosen if maxsize <= 0. (2) To run this on images at resolution between 200 and 300, it is advisable to use a larger maxsize, say between 10 and 14. (3) The best size for dilating to get word masks is optionally returned.
Definition at line 1420 of file jbclass.c.
References boxaDestroy(), boxaGetCount(), ERROR_PTR, GPLOT_LINES, GPLOT_PNG, gplotAddPlot(), gplotCreate(), gplotDestroy(), gplotMakeOutput(), JbFindTemplatesState::i, L_CLONE, L_COPY, MAX_ALLOWED_DILATION, maxsize, NULL, numaAddNumber(), numaCreate(), numaDestroy(), numaGetCount(), numaMakeSequence(), pixaAddPix(), pixaCreate(), pixaDestroy(), pixaGetPix(), pixConnCompBB(), pixCopy(), pixDestroy(), pixErode(), pixMorphSequence(), PROCNAME, SEL_HIT, selCreateBrick(), and selDestroy().
Referenced by jbGetComponents(), pixGetWordBoxesInTextlines(), and pixGetWordsInTextlines().
Input: pixaa (one pixa for each class) &pna (<return> number of samples used to build each composite) &ptat (<return> centroids of bordered composites) Return: pixad (accumulated sum of samples in each class), or null on error
Definition at line 1522 of file jbclass.c.
References ERROR_PTR, JbFindTemplatesState::i, L_ARITH_ADD, L_CLONE, L_INSERT, L_WARNING, JbFindTemplatesState::n, NULL, numaAddNumber(), numaCreate(), PIX_SRC, pixaAddPix(), pixaaGetCount(), pixaaGetPixa(), pixAccumulate(), pixaCentroids(), pixaCreate(), pixaDestroy(), pixaGetCount(), pixaGetPix(), pixaSizeRange(), pixClearAll(), pixCreate(), pixDestroy(), pixGetDepth(), pixInitAccumulate(), pixRasterop(), PROCNAME, ptaAddPt(), ptaCreate(), ptaDestroy(), and ptaGetPt().
Input: pixac (one pix of composites for each class) na (number of samples used for each class composite) Return: pixad (8 bpp templates for each class), or null on error
Definition at line 1612 of file jbclass.c.
References ERROR_PTR, JbFindTemplatesState::i, L_COPY, L_INSERT, JbFindTemplatesState::n, NULL, numaGetFValue(), pixaAddPix(), pixaCreate(), pixaGetCount(), pixaGetPix(), pixDestroy(), pixFinalAccumulate(), pixMultConstAccumulate(), and PROCNAME.
Input: method (JB_RANKHAUS, JB_CORRELATION) components (JB_CONN_COMPS, JB_CHARACTERS, JB_WORDS) Return: jbclasser, or null on error
Definition at line 1657 of file jbclass.c.
References CALLOC, JbFindTemplatesState::classer, JbClasser::components, ERROR_PTR, JB_CHARACTERS, JB_CONN_COMPS, JB_CORRELATION, JB_RANKHAUS, JB_WORDS, JbClasser::method, JbClasser::naarea, JbClasser::naclass, JbClasser::nacomps, JbClasser::nafgt, JbClasser::napage, NULL, numaCreate(), JbClasser::pixaa, pixaaCreate(), pixaCreate(), JbClasser::pixat, JbClasser::pixatd, PROCNAME, JbClasser::ptac, ptaCreate(), JbClasser::ptact, and JbClasser::ptaul.
Referenced by jbCorrelationInitInternal(), and jbRankHausInit().
void jbClasserDestroy | ( | JBCLASSER ** | pclasser | ) |
Definition at line 1697 of file jbclass.c.
References JbFindTemplatesState::classer, FREE, JbClasser::naarea, JbClasser::naclass, JbClasser::nacomps, JbClasser::nafgt, JbClasser::nahash, JbClasser::napage, NULL, numaDestroy(), numaHashDestroy(), JbClasser::pixaa, pixaaDestroy(), pixaDestroy(), JbClasser::pixat, JbClasser::pixatd, JbClasser::ptac, JbClasser::ptact, ptaDestroy(), JbClasser::ptall, JbClasser::ptaul, JbClasser::safiles, and sarrayDestroy().
Referenced by jbCorrelation(), jbRankHaus(), and main().
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,
Definition at line 1744 of file jbclass.c.
References CALLOC, ERROR_PTR, JbClasser::h, JbData::h, JbData::latticeh, JbData::latticew, JbClasser::naclass, JbData::naclass, JbClasser::napage, JbData::napage, JbClasser::nclass, JbData::nclass, JbClasser::npages, JbData::npages, NULL, numaClone(), JbData::pix, pixaDisplayOnLattice(), pixaSizeRange(), JbClasser::pixat, PROCNAME, ptaClone(), JbClasser::ptaul, JbData::ptaul, JbClasser::w, and JbData::w.
Referenced by jbCorrelation(), jbRankHaus(), and main().
void jbDataDestroy | ( | JBDATA ** | pdata | ) |
Definition at line 1785 of file jbclass.c.
References FREE, JbData::naclass, JbData::napage, NULL, numaDestroy(), JbData::pix, pixDestroy(), ptaDestroy(), and JbData::ptaul.
Referenced by jbCorrelation(), jbRankHaus(), and main().
Input: rootname (for output files; everything but the extension) jbdata Return: 0 if OK, 1 on error
Notes: (1) Serialization function that writes data in jbdata to file.
Definition at line 1815 of file jbclass.c.
References buf, ERROR_INT, fopenWriteStream(), JbData::h, JbFindTemplatesState::h, JbFindTemplatesState::i, IFF_PNG, JB_DATA_EXT, JB_TEMPLATE_EXT, L_BUF_SIZE, JbData::latticeh, JbData::latticew, JbData::naclass, JbData::napage, JbData::nclass, JbData::npages, NULL, numaGetIValue(), JbData::pix, pixWrite(), PROCNAME, ptaGetCount(), ptaGetIPt(), JbData::ptaul, JbData::w, and JbFindTemplatesState::w.
Referenced by jbCorrelation(), jbRankHaus(), and main().
JBDATA* jbDataRead | ( | const char * | rootname | ) |
Input: rootname (for template and data files) Return: jbdata, or NULL on error
Definition at line 1875 of file jbclass.c.
References CALLOC, ERROR_PTR, FREE, JbData::h, JbFindTemplatesState::h, JbFindTemplatesState::i, JB_DATA_EXT, JB_TEMPLATE_EXT, l_binaryRead(), L_BUF_SIZE, JbData::latticeh, JbData::latticew, JbData::naclass, JbData::napage, JbData::nclass, JbData::npages, NULL, numaAddNumber(), numaCreate(), JbData::pix, pixRead(), PROCNAME, ptaAddPt(), ptaCreate(), JbData::ptaul, sarrayCreateLinesFromString(), sarrayDestroy(), sarrayGetCount(), sarrayGetString(), size, JbData::w, and JbFindTemplatesState::w.
Referenced by main().
Input: jbdata debugflag (if TRUE, writes into 2 bpp pix and adds component outlines in color) Return: pixa (reconstruction of original images, using templates) or null on error
Definition at line 1970 of file jbclass.c.
References boxCreate(), boxDestroy(), ERROR_PTR, FALSE, JbData::h, JbFindTemplatesState::h, JbFindTemplatesState::i, L_CLONE, L_INSERT, JbData::latticeh, JbData::latticew, JbData::naclass, JbData::napage, JbData::nclass, JbData::npages, NULL, numaGetCount(), numaGetIValue(), JbData::pix, PIX_DST, PIX_SRC, pixaAddPix(), pixaCreate(), pixaCreateFromPix(), pixaDestroy(), pixaGetPix(), pixcmapAddColor(), pixcmapCreate(), pixConvert1To2Cmap(), pixCreate(), pixDestroy(), pixGetHeight(), pixGetWidth(), pixRasterop(), pixRenderBoxArb(), pixSetColormap(), PROCNAME, ptaGetIPt(), JbData::ptaul, JbData::w, and JbFindTemplatesState::w.
Referenced by jbCorrelation(), jbRankHaus(), and main().
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.
Definition at line 2075 of file jbclass.c.
References JbClasser::baseindex, boxaGetBox(), boxaGetCount(), boxDestroy(), boxGetGeometry(), ERROR_INT, finalPositioningForAlignment(), FREE, JbFindTemplatesState::i, L_CLONE, makePixelSumTab8(), JbFindTemplatesState::n, JbClasser::naclass, NULL, numaGetIValue(), pixaGetPix(), JbClasser::pixat, pixDestroy(), PROCNAME, ptaAddPt(), JbClasser::ptac, JbClasser::ptact, ptaGetPt(), JbClasser::ptaul, x1, x2, y1, and y2.
Referenced by jbAddPageComponents().
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.
Definition at line 2163 of file jbclass.c.
References ERROR_INT, JbFindTemplatesState::h, JbFindTemplatesState::i, JB_ADDED_PIXELS, L_CLONE, JbFindTemplatesState::n, JbClasser::naclass, numaGetIValue(), pixaGetPix(), JbClasser::pixat, pixDestroy(), pixGetHeight(), PROCNAME, ptaAddPt(), ptaCreate(), ptaDestroy(), ptaGetCount(), ptaGetIPt(), JbClasser::ptall, JbClasser::ptaul, x1, and y1.
const l_int32 JB_ADDED_PIXELS = 6 [static] |
Definition at line 207 of file jbclass.c.
Referenced by finalPositioningForAlignment(), findSimilarSizedTemplatesInit(), findSimilarSizedTemplatesNext(), jbClassifyCorrelation(), jbClassifyRankHaus(), and jbGetLLCorners().
const l_int32 MAX_DIFF_WIDTH = 2 [static] |
Definition at line 211 of file jbclass.c.
Referenced by jbClassifyCorrelation(), and jbClassifyRankHaus().
const l_int32 MAX_DIFF_HEIGHT = 2 [static] |
Definition at line 212 of file jbclass.c.
Referenced by jbClassifyCorrelation(), and jbClassifyRankHaus().
const l_int32 MAX_CONN_COMP_WIDTH = 350 [static] |
Definition at line 221 of file jbclass.c.
Referenced by jbCorrelationInitInternal(), and jbRankHausInit().
const l_int32 MAX_CHAR_COMP_WIDTH = 350 [static] |
Definition at line 222 of file jbclass.c.
Referenced by jbCorrelationInitInternal(), and jbRankHausInit().
const l_int32 MAX_WORD_COMP_WIDTH = 1000 [static] |
Definition at line 223 of file jbclass.c.
Referenced by jbCorrelationInitInternal(), and jbRankHausInit().
const l_int32 MAX_COMP_HEIGHT = 120 [static] |
Definition at line 224 of file jbclass.c.
Referenced by jbCorrelationInitInternal(), and jbRankHausInit().
int two_by_two_walk[50] [static] |
{ 0, 0, 0, 1, -1, 0, 0, -1, 1, 0, -1, 1, 1, 1, -1, -1, 1, -1, 0, -2, 2, 0, 0, 2, -2, 0, -1, -2, 1, -2, 2, -1, 2, 1, 1, 2, -1, 2, -2, 1, -2, -1, -2, -2, 2, -2, 2, 2, -2, 2}
Definition at line 2210 of file jbclass.c.
Referenced by findSimilarSizedTemplatesNext().