|
| l_int32 | pixGetRegionsBinary (PIX *pixs, PIX **ppixhm, PIX **ppixtm, PIX **ppixtb, PIXA *pixadb) |
| |
| PIX * | pixGenHalftoneMask (PIX *pixs, PIX **ppixtext, l_int32 *phtfound, l_int32 debug) |
| |
| PIX * | pixGenerateHalftoneMask (PIX *pixs, PIX **ppixtext, l_int32 *phtfound, PIXA *pixadb) |
| |
| PIX * | pixGenTextlineMask (PIX *pixs, PIX **ppixvws, l_int32 *ptlfound, PIXA *pixadb) |
| |
| PIX * | pixGenTextblockMask (PIX *pixs, PIX *pixvws, PIXA *pixadb) |
| |
| BOX * | pixFindPageForeground (PIX *pixs, l_int32 threshold, l_int32 mindist, l_int32 erasedist, l_int32 pagenum, l_int32 showmorph, l_int32 display, const char *pdfdir) |
| |
| l_int32 | pixSplitIntoCharacters (PIX *pixs, l_int32 minw, l_int32 minh, BOXA **pboxa, PIXA **ppixa, PIX **ppixdebug) |
| |
| BOXA * | pixSplitComponentWithProfile (PIX *pixs, l_int32 delta, l_int32 mindel, PIX **ppixdebug) |
| |
| PIXA * | pixExtractTextlines (PIX *pixs, l_int32 maxw, l_int32 maxh, l_int32 minw, l_int32 minh, l_int32 adjw, l_int32 adjh, PIXA *pixadb) |
| |
| PIXA * | pixExtractRawTextlines (PIX *pixs, l_int32 maxw, l_int32 maxh, l_int32 adjw, l_int32 adjh, PIXA *pixadb) |
| |
| l_int32 | pixCountTextColumns (PIX *pixs, l_float32 deltafract, l_float32 peakfract, l_float32 clipfract, l_int32 *pncols, PIXA *pixadb) |
| |
| l_int32 | pixDecideIfText (PIX *pixs, BOX *box, l_int32 *pistext, PIXA *pixadb) |
| |
| l_int32 | pixFindThreshFgExtent (PIX *pixs, l_int32 thresh, l_int32 *ptop, l_int32 *pbot) |
| |
| l_int32 | pixDecideIfTable (PIX *pixs, BOX *box, l_int32 orient, l_int32 *pscore, PIXA *pixadb) |
| |
| PIX * | pixPrepare1bpp (PIX *pixs, BOX *box, l_float32 cropfract, l_int32 outres) |
| |
| l_int32 | pixEstimateBackground (PIX *pixs, l_int32 darkthresh, l_float32 edgecrop, l_int32 *pbg) |
| |
| l_int32 | pixFindLargeRectangles (PIX *pixs, l_int32 polarity, l_int32 nrect, BOXA **pboxa, PIX **ppixdb) |
| |
| l_int32 | pixFindLargestRectangle (PIX *pixs, l_int32 polarity, BOX **pbox, PIX **ppixdb) |
| |
Top level page segmentation
l_int32 pixGetRegionsBinary()
Halftone region extraction
PIX *pixGenHalftoneMask() **Deprecated wrapper**
PIX *pixGenerateHalftoneMask()
Textline extraction
PIX *pixGenTextlineMask()
Textblock extraction
PIX *pixGenTextblockMask()
Location of page foreground
PIX *pixFindPageForeground()
Extraction of characters from image with only text
l_int32 pixSplitIntoCharacters()
BOXA *pixSplitComponentWithProfile()
Extraction of lines of text
PIXA *pixExtractTextlines()
PIXA *pixExtractRawTextlines()
How many text columns
l_int32 pixCountTextColumns()
Decision: text vs photo
l_int32 pixDecideIfText()
l_int32 pixFindThreshFgExtent()
Decision: table vs text
l_int32 pixDecideIfTable()
Pix *pixPrepare1bpp()
Estimate the grayscale background value
l_int32 pixEstimateBackground()
Largest white or black rectangles in an image
l_int32 pixFindLargeRectangles()
l_int32 pixFindLargestRectangle()
Definition in file pageseg.c.
| l_int32 pixCountTextColumns |
( |
PIX * |
pixs, |
|
|
l_float32 |
deltafract, |
|
|
l_float32 |
peakfract, |
|
|
l_float32 |
clipfract, |
|
|
l_int32 * |
pncols, |
|
|
PIXA * |
pixadb |
|
) |
| |
pixCountTextColumns()
- Parameters
-
| [in] | pixs | 1 bpp |
| [in] | deltafract | fraction of (max - min) to be used in the delta for extrema finding; typ 0.3 |
| [in] | peakfract | fraction of (max - min) to be used to threshold the peak value; typ. 0.5 |
| [in] | clipfract | fraction of image dimension removed on each side; typ. 0.1, which leaves w and h reduced by 0.8 |
| [out] | pncols | number of columns; -1 if not determined |
| [in] | pixadb | [optional] pre-allocated, for showing intermediate computation; use null to skip |
- Returns
- 0 if OK, 1 on error
Notes:
(1) It is assumed that pixs has the correct resolution set.
If the resolution is 0, we set to 300 and issue a warning.
(2) If necessary, the image is scaled to between 37 and 75 ppi;
most of the processing is done at this resolution.
(3) If no text is found (essentially a blank page),
this returns ncols = 0.
(4) For debug output, input a pre-allocated pixa.
Definition at line 1224 of file pageseg.c.
Referenced by dewarpaApplyInit().
| l_int32 pixDecideIfTable |
( |
PIX * |
pixs, |
|
|
BOX * |
box, |
|
|
l_int32 |
orient, |
|
|
l_int32 * |
pscore, |
|
|
PIXA * |
pixadb |
|
) |
| |
pixDecideIfTable()
- Parameters
-
| [in] | pixs | any depth, any resolution >= 75 ppi |
| [in] | box | [optional] if null, use entire pixs |
| [in] | orient | L_PORTRAIT_MODE, L_LANDSCAPE_MODE |
| [out] | pscore | 0 - 4; -1 if not determined |
| [in] | pixadb | [optional] pre-allocated, for showing intermediate computation; use NULL to skip |
- Returns
- 0 if OK, 1 on error
Notes:
(1) It is assumed that pixs has the correct resolution set.
If the resolution is 0, we assume it is 300 ppi and issue a warning.
(2) If orient == L_LANDSCAPE_MODE, the image is rotated 90 degrees
clockwise before being analyzed.
(3) The interpretation of the returned score:
-1 undetermined
0 no table
1 unlikely to have a table
2 likely to have a table
3 even more likely to have a table
4 extremely likely to have a table
* Setting the condition for finding a table at score >= 2 works
well, except for false positives on kanji and landscape text.
* These false positives can be removed by setting the condition
at score >= 3, but recall is lowered because it will not find
tables without either horizontal or vertical lines.
(4) Most of the processing takes place at 75 ppi.
(5) Internally, three numbers are determined, for horizontal and
vertical fg lines, and for vertical bg lines. From these,
four tests are made to decide if there is a table occupying
a significant part of the image.
(6) Images have arbitrary content and would be likely to trigger
this detector, so they are checked for first, and if found,
return with a 0 (no table) score.
(7) Musical scores (tablature) are likely to trigger the detector.
(8) Tables of content with more than 2 columns are likely to
trigger the detector.
(9) For debug output, input a pre-allocated pixa.
Definition at line 1628 of file pageseg.c.
References L_COPY, L_INSERT, L_LANDSCAPE_MODE, L_SELECT_IF_GTE, L_SELECT_WIDTH, pixaAddPix(), pixClone(), pixCountConnComp(), pixDeskewBoth(), pixDestroy(), pixDilateBrick(), pixGenerateHalftoneMask(), pixInvert(), pixMorphSequence(), pixOr(), pixPrepare1bpp(), pixRotate90(), pixScale(), pixSeedfillBinary(), pixSelectBySize(), pixSubtract(), and pixZero().
| l_int32 pixDecideIfText |
( |
PIX * |
pixs, |
|
|
BOX * |
box, |
|
|
l_int32 * |
pistext, |
|
|
PIXA * |
pixadb |
|
) |
| |
pixDecideIfText()
- Parameters
-
| [in] | pixs | any depth |
| [in] | box | [optional] if null, use entire pixs |
| [out] | pistext | 1 if text; 0 if photo; -1 if not determined or empty |
| [in] | pixadb | [optional] pre-allocated, for showing intermediate computation; use NULL to skip |
- Returns
- 0 if OK, 1 on error
Notes:
(1) It is assumed that pixs has the correct resolution set.
If the resolution is 0, we set to 300 and issue a warning.
(2) If necessary, the image is scaled to 300 ppi; most of the
processing is done at this resolution.
(3) Text is assumed to be in horizontal lines.
(4) Because thin vertical lines are removed before filtering for
text lines, this should identify tables as text.
(5) If box is null and pixs contains both text lines and line art,
this function might return istext == true.
(6) If the input pixs is empty, or for some other reason the
result can not be determined, return -1.
(7) For debug output, input a pre-allocated pixa.
Definition at line 1372 of file pageseg.c.
References pixDestroy(), pixPrepare1bpp(), and pixZero().
| PIXA* pixExtractRawTextlines |
( |
PIX * |
pixs, |
|
|
l_int32 |
maxw, |
|
|
l_int32 |
maxh, |
|
|
l_int32 |
adjw, |
|
|
l_int32 |
adjh, |
|
|
PIXA * |
pixadb |
|
) |
| |
pixExtractRawTextlines()
- Parameters
-
| [in] | pixs | any depth, assumed to have nearly horizontal text |
| [in] | maxw,maxh | initial filtering: remove any components in pixs with components larger than maxw or maxh; use 0 for default values. |
| [in] | adjw,adjh | final adjustment of boxes representing each text line. If > 0, these increase the box size at each edge by this amount. |
| [in] | pixadb | pixa for saving intermediate steps; NULL to omit |
- Returns
- pixa of textline images, including bounding boxes, or NULL on error
Notes:
(1) This function assumes that textlines have sufficient
vertical separation and small enough skew so that a
horizontal dilation sufficient to join words will not join
textlines. It aggressively joins textlines across multiple
columns, so if that is not desired, you must either (a) make
sure that pixs is a single column of text or (b) use instead
pixExtractTextlines(), which is more conservative
about joining text fragments that have vertical overlap.
(2) This first removes components from pixs that are either
very wide (> maxw) or very tall (> maxh).
(3) For reasonable accuracy, the resolution of pixs should be
at least 100 ppi. For reasonable efficiency, the resolution
should not exceed 600 ppi.
(4) This can be used to determine if some region of a scanned
image is horizontal text.
(5) As an example, for a pix with resolution 300 ppi, a reasonable
set of parameters is:
pixExtractRawTextlines(pix, 150, 150, 0, 0, NULL);
(6) The output pixa is composed of subimages, one for each textline,
and the boxa in the pixa tells where in pixs each textline goes.
Definition at line 1096 of file pageseg.c.
| PIXA* pixExtractTextlines |
( |
PIX * |
pixs, |
|
|
l_int32 |
maxw, |
|
|
l_int32 |
maxh, |
|
|
l_int32 |
minw, |
|
|
l_int32 |
minh, |
|
|
l_int32 |
adjw, |
|
|
l_int32 |
adjh, |
|
|
PIXA * |
pixadb |
|
) |
| |
pixExtractTextlines()
- Parameters
-
| [in] | pixs | any depth, assumed to have nearly horizontal text |
| [in] | maxw,maxh | initial filtering: remove any components in pixs with components larger than maxw or maxh |
| [in] | minw,minh | final filtering: remove extracted 'lines' with sizes smaller than minw or minh; use 0 for default. |
| [in] | adjw,adjh | final adjustment of boxes representing each text line. If > 0, these increase the box size at each edge by this amount. |
| [in] | pixadb | pixa for saving intermediate steps; NULL to omit |
- Returns
- pixa of textline images, including bounding boxes, or NULL on error
Notes:
(1) This function assumes that textline fragments have sufficient
vertical separation and small enough skew so that a
horizontal dilation sufficient to join words will not join
textlines. It does not guarantee that horizontally adjacent
textline fragments on the same line will be joined.
(2) For images with multiple columns, it attempts to avoid joining
textlines across the space between columns. If that is not
a concern, you can also use pixExtractRawTextlines(),
which will join them with alacrity.
(3) This first removes components from pixs that are either
wide (> maxw) or tall (> maxh).
(4) A final filtering operation removes small components, such
that width < minw or height < minh.
(5) For reasonable accuracy, the resolution of pixs should be
at least 100 ppi. For reasonable efficiency, the resolution
should not exceed 600 ppi.
(6) This can be used to determine if some region of a scanned
image is horizontal text.
(7) As an example, for a pix with resolution 300 ppi, a reasonable
set of parameters is:
pixExtractTextlines(pix, 150, 150, 36, 20, 5, 5, NULL);
The defaults minw and minh for 300 ppi are about 36 and 20,
so the same result is obtained with:
pixExtractTextlines(pix, 150, 150, 0, 0, 5, 5, NULL);
(8) The output pixa is composed of subimages, one for each textline,
and the boxa in the pixa tells where in pixs each textline goes.
Definition at line 956 of file pageseg.c.
| l_int32 pixFindLargeRectangles |
( |
PIX * |
pixs, |
|
|
l_int32 |
polarity, |
|
|
l_int32 |
nrect, |
|
|
BOXA ** |
pboxa, |
|
|
PIX ** |
ppixdb |
|
) |
| |
pixFindLargeRectangles()
- Parameters
-
| [in] | pixs | 1 bpp |
| [in] | polarity | 0 within background, 1 within foreground |
| [in] | nrect | number of rectangles to be found |
| [out] | pboxa | largest rectangles, sorted by decreasing area |
| [in,out] | ppixdb | optional return output with rectangles drawn on it |
- Returns
- 0 if OK, 1 on error
Notes:
(1) This does a greedy search to find the largest rectangles,
either black or white and without overlaps, in pix.
(2) See pixFindLargestRectangle(), which is called multiple
times, for details. On each call, the largest rectangle
found is painted, so that none of its pixels can be
used later, before calling it again.
(3) This function is surprisingly fast. Although
pixFindLargestRectangle() runs at about 50 MPix/sec, when it
is run multiple times by pixFindLargeRectangles(), it processes
at 150 - 250 MPix/sec, and the time is approximately linear
in nrect. For example, for a 1 MPix image, searching for
the largest 50 boxes takes about 0.2 seconds.
Definition at line 1947 of file pageseg.c.
| l_int32 pixFindLargestRectangle |
( |
PIX * |
pixs, |
|
|
l_int32 |
polarity, |
|
|
BOX ** |
pbox, |
|
|
PIX ** |
ppixdb |
|
) |
| |
pixFindLargestRectangle()
- Parameters
-
| [in] | pixs | 1 bpp |
| [in] | polarity | 0 within background, 1 within foreground |
| [out] | pbox | largest area rectangle |
| [in,out] | ppixdb | optional return output with rectangle drawn on it |
- Returns
- 0 if OK, 1 on error
Notes:
(1) This is a simple and elegant solution to a problem in
computational geometry that at first appears to be quite
difficult: what is the largest rectangle that can be
placed in the image, covering only pixels of one polarity
(bg or fg)? The solution is O(n), where n is the number
of pixels in the image, and it requires nothing more than
using a simple recursion relation in a single sweep of the image.
(2) In a sweep from UL to LR with left-to-right being the fast
direction, calculate the largest white rectangle at (x, y),
using previously calculated values at pixels #1 and #2:
#1: (x, y - 1)
#2: (x - 1, y)
We also need the most recent "black" pixels that were seen
in the current row and column.
Consider the largest area. There are only two possibilities:
(a) Min(w(1), horizdist) * (h(1) + 1)
(b) Min(h(2), vertdist) * (w(2) + 1)
where
horizdist: the distance from the rightmost "black" pixel seen
in the current row across to the current pixel
vertdist: the distance from the lowest "black" pixel seen
in the current column down to the current pixel
and we choose the Max of (a) and (b).
(3) To convince yourself that these recursion relations are correct,
it helps to draw the maximum rectangles at #1 and #2.
Then for #1, you try to extend the rectangle down one line,
so that the height is h(1) + 1. Do you get the full
width of #1, w(1)? It depends on where the black pixels are
in the current row. You know the final width is bounded by w(1)
and w(2) + 1, but the actual value depends on the distribution
of black pixels in the current row that are at a distance
from the current pixel that is between these limits.
We call that value "horizdist", and the area is then given
by the expression (a) above. Using similar reasoning for #2,
where you attempt to extend the rectangle to the right
by 1 pixel, you arrive at (b). The largest rectangle is
then found by taking the Max.
Definition at line 2049 of file pageseg.c.
References pixCreate(), pixGetData(), pixGetDimensions(), and pixGetLinePtrs().
| BOX* pixFindPageForeground |
( |
PIX * |
pixs, |
|
|
l_int32 |
threshold, |
|
|
l_int32 |
mindist, |
|
|
l_int32 |
erasedist, |
|
|
l_int32 |
pagenum, |
|
|
l_int32 |
showmorph, |
|
|
l_int32 |
display, |
|
|
const char * |
pdfdir |
|
) |
| |
pixFindPageForeground()
- Parameters
-
| [in] | pixs | full resolution (any type or depth |
| [in] | threshold | for binarization; typically about 128 |
| [in] | mindist | min distance of text from border to allow cleaning near border; at 2x reduction, this should be larger than 50; typically about 70 |
| [in] | erasedist | when conditions are satisfied, erase anything within this distance of the edge; typically 30 at 2x reduction |
| [in] | pagenum | use for debugging when called repeatedly; labels debug images that are assembled into pdfdir |
| [in] | showmorph | set to a negative integer to show steps in generating masks; this is typically used for debugging region extraction |
| [in] | display | set to 1 to display mask and selected region for debugging a single page |
| [in] | pdfdir | subdirectory of /tmp where images showing the result are placed when called repeatedly; use null if no output requested |
- Returns
- box region including foreground, with some pixel noise removed, or NULL if not found
Notes:
(1) This doesn't simply crop to the fg. It attempts to remove
pixel noise and junk at the edge of the image before cropping.
The input threshold is used if pixs is not 1 bpp.
(2) There are several debugging options, determined by the
last 4 arguments.
(3) This is not intended to work on small thumbnails. The
dimensions of pixs must be at least MinWidth x MinHeight.
(4) If you want pdf output of results when called repeatedly,
the pagenum arg labels the images written, which go into
/tmp/lept/<pdfdir>/<pagenum>.png. In that case,
you would clean out the /tmp directory before calling this
function on each page:
lept_rmdir("/lept/<pdfdir>");
lept_mkdir("/lept/<pdfdir>");
Definition at line 556 of file pageseg.c.
References pixGetDimensions().
| PIX* pixGenTextblockMask |
( |
PIX * |
pixs, |
|
|
PIX * |
pixvws, |
|
|
PIXA * |
pixadb |
|
) |
| |
pixGenTextblockMask()
- Parameters
-
| [in] | pixs | 1 bpp, textline mask, assumed to be 150 to 200 ppi |
| [in] | pixvws | vertical white space mask |
| [in] | pixadb | input for collecting debug pix; use NULL to skip |
- Returns
- pixd textblock mask, or NULL on error
Notes:
(1) Both the input masks (textline and vertical white space) and
the returned textblock mask are at the same resolution.
(2) This is not intended to work on small thumbnails. The
dimensions of pixs must be at least MinWidth x MinHeight.
(3) The result is somewhat noisy, in that small "blocks" of
text may be included. These can be removed by post-processing,
using, e.g.,
pixSelectBySize(pix, 60, 60, 4, L_SELECT_IF_EITHER,
L_SELECT_IF_GTE, NULL);
Definition at line 465 of file pageseg.c.
| PIX* pixPrepare1bpp |
( |
PIX * |
pixs, |
|
|
BOX * |
box, |
|
|
l_float32 |
cropfract, |
|
|
l_int32 |
outres |
|
) |
| |
pixPrepare1bpp()
- Parameters
-
| [in] | pixs | any depth |
| [in] | box | [optional] if null, use entire pixs |
| [in] | cropfract | fraction to be removed from the boundary; use 0.0 to retain the entire image |
| [in] | outres | desired resolution of output image; if the input image resolution is not set, assume 300 ppi; use 0 to skip scaling. |
- Returns
- pixd if OK, NULL on error
Notes: (1) This handles some common pre-processing operations, where the page segmentation algorithm takes a 1 bpp image.
Definition at line 1778 of file pageseg.c.
References boxCreate(), boxDestroy(), pixClipRectangle(), and pixGetDimensions().
Referenced by pixDecideIfTable(), and pixDecideIfText().