#include <getLines.h>
getLines.cpp contains the getLines class source code. Given a deskewed, oriented text image with dark machine print text on a light background, this code will calculate text line information based on the connected components. The image must be deskewed and oriented in order to receive meaningful results. It was originally used in code called "CollectFeatureData" which made use of subroutines from the TwoBit image processing library.
The algorithm utilized by the getLines class has proven robust given text images with low resolution, broken characters, connected scripts (e.g. Arabic), multi-component character scripts (e.g. Chinese), and noise.
There are five basic steps to performing text line detection:
Computing connected components.
Filtering connected components based on size and density.
Computing line segment based on nearby neighbors.
The centroids of the filtered connected components are used to form an initial set of line segments. This is done by connecting each component to its nearest neighbor in a triangular region to the right while applying distance constraints.
Iteratively merging line segments to form new line segments. This is done based on the minimum distance between line segments and horizontal and vertical line separation. Merging continues until no more merges occur.
Final line segment filtering.
In the below diagram, assume the skewed word "HELLO" has been correctly identified as comprising a text line. The central text line is defined by endpoints {(x3, y3), (x4, y4)}. The bounding box which encompasses "HELLO" is defined by upper left coordinate (x1, y1) and lower right coordinate (x2, y2). The pixel height of the text line is y2-y1=9 and the pixel width is x2-x3=38. The density of the text line is 0.2135 which is 73 text pixels divided by the bounding box area (9x38). The slope of the central text line is (y3-y4)/(x3-x4). The y-intercept of the central text line is y3-((y3-y4)/(x3-x4))*x3. The upper extent is min(y3-y1, y4-y1) and the lower extent is max(y3-y2, y4-y2).
(x1, y1)
|
v
|--------------------------------------|
| #### |
| # # #|
| #### # # # #|
|# # ## # # -------|<-(x4, y4)
|# # # #### # ----------/ # #|
|###### ##---------/ # #### |
(x3, y3)->|---------/ # ## ###### |
|# # # #### #### |
|# # ## |
|--------------------------------------|
^
|
(x2, y2)
Written by AMS on July 20, 2004 using code and documentation from LMG.
Definition at line 269 of file getLines.h.
getLines::getLines | ( | DLImage | emu | ) |
Constructor that takes a DLImage as input. Allocate memory and initialize variables.
emu | The DLImage of the image to process. The getLines algorithm operates on binary image data. If a color or grayscale image is passed in binarization will be performed using the DLBitsPerPixelConverter::dlDownscaleColor2Gray_global() and/or DLBitsPerPixelConverter::dlDownscaleGray2Binary_global() routines. If alternate binarization is desired it should be performed priof to invoking this class. |
getLines::~getLines | ( | ) |
Destructor. Clear allocated memory.
void getLines::dlPrintLineInfo | ( | ) |
Method to print text line information to standard output. This includes the upper right and lower left bounding box information.
void getLines::dlPrintLineInfo1 | ( | std::string | fname, | |
DLlineInfo * | , | |||
int | ||||
) |
void getLines::dlPrintLineInfo | ( | std::string | fname | ) |
Method to print line information to standard output and create an image called fname which contains the input image with text line bounding boxes and central text lines superimposed.
fname | Name of output image. |
void getLines::dlRecalculate | ( | ) |
After setting new parameters with set methods, identify new text lines using these parameters. The only parameters that may be adjusted are the following which are described in greater detail in the Member Data Documentation section:
_densityCCLess: Density upper threshold.
_lowCCHeight: Lower pixel height threshold.
_highCCHeight: Upper pixel height threshold.
_lowCCWidth: Lower pixel width threshold.
_highCCWidth: Upper pixel width threshold.
_maxToMedianRatio: Upper height factor threshold.
_minAvgHeight: Lower pixel height threshold.
float getLines::dlGetAvgHeight | ( | ) | const [inline] |
Return the pixel height of the average (arithmetic mean) length line of text.
Definition at line 336 of file getLines.h.
References _avgHeightText.
float getLines::dlGetAvgSlope | ( | ) | const [inline] |
Return the average (arithmetic mean) slope value for the central text lines.
Definition at line 341 of file getLines.h.
References _avgSlope.
float getLines::dlGetAvgWidth | ( | ) | const [inline] |
Return the pixel width of the average (arithmetic mean) length line of text.
Definition at line 346 of file getLines.h.
References _avgWidthText.
DLlineInfo* getLines::dlGetInfo | ( | ) | const [inline] |
Return text line information in an array of DLlineInfo structures. Knowledge of _lineCount is required to access all terms.
Definition at line 351 of file getLines.h.
References imageObj.
int getLines::dlGetLineCount | ( | ) | const [inline] |
Return the text line count.
Definition at line 355 of file getLines.h.
References _lineCount.
float getLines::dlGetMaxIntercept | ( | ) | const [inline] |
Return the largest y-ntercept value for the central text lines.
Definition at line 359 of file getLines.h.
References _maxIntercept.
float getLines::dlGetMaxSlope | ( | ) | const [inline] |
Return the largest slope value for the central text lines.
Definition at line 363 of file getLines.h.
References _maxSlope.
int getLines::dlGetMaxTextCol | ( | ) | const [inline] |
Return the largest pixel column number which bounds text.
Definition at line 367 of file getLines.h.
References _maxXText.
int getLines::dlGetMaxTextHeight | ( | ) | const [inline] |
Return the pixel height of the tallest line of text.
Definition at line 371 of file getLines.h.
References _maxHeightText.
int getLines::dlGetMaxTextRow | ( | ) | const [inline] |
Return the largest pixel row number which bounds text.
Definition at line 375 of file getLines.h.
References _maxYText.
int getLines::dlGetMaxTextWidth | ( | ) | const [inline] |
Return the pixel width of the widest line of text.
Definition at line 379 of file getLines.h.
References _maxWidthText.
float getLines::dlGetMinIntercept | ( | ) | const [inline] |
Return the smallest y-ntercept value for the central text lines.
Definition at line 383 of file getLines.h.
References _minIntercept.
float getLines::dlGetMinSlope | ( | ) | const [inline] |
Return the smallest slope value for the central text lines.
Definition at line 387 of file getLines.h.
References _minSlope.
int getLines::dlGetMinTextCol | ( | ) | const [inline] |
Return the smallest pixel column number which bounds text.
Definition at line 391 of file getLines.h.
References _minXText.
int getLines::dlGetMinTextHeight | ( | ) | const [inline] |
Return the pixel height of the shortest line of text.
Definition at line 395 of file getLines.h.
References _minHeightText.
int getLines::dlGetMinTextRow | ( | ) | const [inline] |
Return the smallest pixel column number which bounds text.
Definition at line 399 of file getLines.h.
References _minYText.
int getLines::dlGetMinTextWidth | ( | ) | const [inline] |
Return the pixel height of the narrowest line of text.
Definition at line 403 of file getLines.h.
References _minWidthText.
float getLines::dlGetSlopeVariance | ( | ) | const [inline] |
Return the variance of the slope values for the central text lines. This value is the population variance which is also the second moment of the sample about its mean.
Definition at line 409 of file getLines.h.
References _varSlope.
float getLines::dlGetTextVarianceHeight | ( | ) | const [inline] |
Return the variance of the pixel text heights. This value is the population variance which is also the second moment of the sample about its mean.
Definition at line 415 of file getLines.h.
References _varHeightText.
float getLines::dlGetTextVarianceWidth | ( | ) | const [inline] |
Return the variance of the pixel text widths. This value is the population variance which is also the second moment of the sample about its mean.
Definition at line 422 of file getLines.h.
References _varWidthText.
void getLines::dlSetFilterCCDensity | ( | float | dens | ) | [inline] |
Only save those connected components that have a density less than or equal to dens; the density is the ratio of pixels that are connected components to the total number of connected componets in the bounding box that contains the connected component. After calling this method, the dlRecalculate() method must be run in order for the new parameter to take effect.
dens | Density upper threshold. |
Definition at line 436 of file getLines.h.
References _densityCCLess.
void getLines::dlSetFilterCCHeightBetween | ( | int | low, | |
int | high | |||
) | [inline] |
Only save those connected components that have a normalized pixel height between low and high inclusive. After calling this method, the dlRecalculate() method must be run in order for the new parameter to take effect.
low | Lower pixel height threshold. | |
high | Upper pixel height threshold. |
Definition at line 445 of file getLines.h.
References _highCCHeight, and _lowCCHeight.
void getLines::dlSetFilterCCWidthBetween | ( | int | low, | |
int | high | |||
) | [inline] |
Only save those connected components that have a normalized pixel width between low and high inclusive. After calling this method, the dlRecalculate() method must be run in order for the new parameter to take effect.
low | Lower pixel width threshold. | |
high | Upper pixel width threshold. |
Definition at line 454 of file getLines.h.
References _highCCWidth, and _lowCCWidth.
void getLines::dlSetMaxToMedianRatio | ( | float | max | ) | [inline] |
Any connected component whose height is more than max times the median height is removed. After calling this method, the dlRecalculate() method must be run in order for the new parameter to take effect.
max | Upper height factor threshold. |
Definition at line 462 of file getLines.h.
References _maxToMedianRatio.
void getLines::dlSetMinAvgHeight | ( | int | min | ) | [inline] |
Only count text lines whose normalized average (arithmetic mean) pixel heights are greater than min. After calling this method, the dlRecalculate() method must be run in order for the new parameter to take effect.
min | Lower pixel height threshold. |
Definition at line 470 of file getLines.h.
References _minAvgHeight.
static string getLines::dlGetVersionInfo | ( | ) | [static] |
Text line information stored in an array of DLlineInfo structures. Knowledge of _lineCount is required to access all terms.
Definition at line 277 of file getLines.h.
Referenced by dlGetInfo().
float getLines::_avgHeightText [protected] |
The pixel height of the average (arithmetic mean) line of text.
Definition at line 481 of file getLines.h.
Referenced by dlGetAvgHeight().
float getLines::_avgSlope [protected] |
The average (arithmetic mean) slope value for the central text lines.
Definition at line 485 of file getLines.h.
Referenced by dlGetAvgSlope().
float getLines::_avgWidthText [protected] |
The pixel width of the average (arithmetic mean) line of text.
Definition at line 488 of file getLines.h.
Referenced by dlGetAvgWidth().
int getLines::_lineCount [protected] |
The total number of text lines.
Definition at line 491 of file getLines.h.
Referenced by dlGetLineCount().
int getLines::_maxHeightText [protected] |
The pixel height of the tallest line of text.
Definition at line 494 of file getLines.h.
Referenced by dlGetMaxTextHeight().
float getLines::_maxIntercept [protected] |
The largest y-intercept value for a central text line.
Definition at line 497 of file getLines.h.
Referenced by dlGetMaxIntercept().
float getLines::_maxSlope [protected] |
The largest slope value for a central text line.
Definition at line 500 of file getLines.h.
Referenced by dlGetMaxSlope().
int getLines::_maxWidthText [protected] |
The pixel width of the widest line of text.
Definition at line 503 of file getLines.h.
Referenced by dlGetMaxTextWidth().
int getLines::_maxXText [protected] |
The largest (rightmost) column number which bounds text.
Definition at line 506 of file getLines.h.
Referenced by dlGetMaxTextCol().
int getLines::_maxYText [protected] |
The largest (downwardmost) row number which bounds text.
Definition at line 509 of file getLines.h.
Referenced by dlGetMaxTextRow().
int getLines::_minHeightText [protected] |
The pixel height of the shortest line of text.
Definition at line 512 of file getLines.h.
Referenced by dlGetMinTextHeight().
float getLines::_minIntercept [protected] |
The smallest y-intercept value for a central text line.
Definition at line 515 of file getLines.h.
Referenced by dlGetMinIntercept().
float getLines::_minSlope [protected] |
The smallest slope value for a central text line.
Definition at line 518 of file getLines.h.
Referenced by dlGetMinSlope().
int getLines::_minWidthText [protected] |
The pixel width of the shortest line of text.
Definition at line 521 of file getLines.h.
Referenced by dlGetMinTextWidth().
int getLines::_minXText [protected] |
The smallest (leftmost) column number which bounds text.
Definition at line 524 of file getLines.h.
Referenced by dlGetMinTextCol().
int getLines::_minYText [protected] |
The smallest (uppermost) row number which bounds text.
Definition at line 527 of file getLines.h.
Referenced by dlGetMinTextRow().
float getLines::_varHeightText [protected] |
The variance of the text heights.
Definition at line 530 of file getLines.h.
Referenced by dlGetTextVarianceHeight().
float getLines::_varSlope [protected] |
The variance of the slope values for the central text lines.
Definition at line 533 of file getLines.h.
Referenced by dlGetSlopeVariance().
float getLines::_varWidthText [protected] |
The variance of the text widths.
Definition at line 536 of file getLines.h.
Referenced by dlGetTextVarianceWidth().
float getLines::_densityCCLess [protected] |
Connected components to be used for text line identification must have a ratio of connected components pixels to pixel count in the bounding box area less than or equal to this value.
Definition at line 545 of file getLines.h.
Referenced by dlSetFilterCCDensity().
int getLines::_highCCHeight [protected] |
Connected components to be used for text line identification must have a height less than or equal to this value.
Definition at line 549 of file getLines.h.
Referenced by dlSetFilterCCHeightBetween().
int getLines::_highCCWidth [protected] |
Connected components to be used for text line identification must have a width less than or equal to this value.
Definition at line 553 of file getLines.h.
Referenced by dlSetFilterCCWidthBetween().
int getLines::_lowCCHeight [protected] |
Connected components to be used for text line identification must have a height greater than or equal to this value.
Definition at line 557 of file getLines.h.
Referenced by dlSetFilterCCHeightBetween().
int getLines::_lowCCWidth [protected] |
Connected components to be used for text line identification must have a width greater than or equal to this value.
Definition at line 561 of file getLines.h.
Referenced by dlSetFilterCCWidthBetween().
float getLines::_maxToMedianRatio [protected] |
Connected components to be used for text line identification must have a height that is not more than the median height times this value.
Definition at line 566 of file getLines.h.
Referenced by dlSetMaxToMedianRatio().
int getLines::_minAvgHeight [protected] |
The only text lines considered are those which are greater than this value in average (arithmetic mean) pixel height.
Definition at line 570 of file getLines.h.
Referenced by dlSetMinAvgHeight().