Line detection

Enumerations

pylena.scribo.e_segdet_preprocess = <class 'pylena.pylena_cxx.scribo.e_segdet_preprocess'>

Members:

NONE : Do not perform any post processing before line detection

BLACK_TOP_HAT : Perform a black top hat as preprocessing to remove the background of the input image

pylena.scribo.e_segdet_process_traversal_mode = <class 'pylena.pylena_cxx.scribo.e_segdet_process_traversal_mode'>

Members:

HORIZONTAL : To perform the line detection only horizontaly

VERTICAL : To perform the line detection only verticaly

HORIZONTAL_VERTICAL : To perform the line detection both horizontaly and verticaly

pylena.scribo.e_segdet_process_tracking = <class 'pylena.pylena_cxx.scribo.e_segdet_process_tracking'>

Members:

KALMAN : Kalman Filters following classics prediction and correction based on IRISA article

ONE_EURO : One Euro Filter (modification from Nicolas Roussel code)

DOUBLE_EXPONENTIAL : Double exponential filter

LAST_INTEGRATION : Last integration predictor

SIMPLE_MOVING_AVERAGE : Simple moving average

EXPONENTIAL_MOVING_AVERAGE : Exponential moving average

pylena.scribo.e_segdet_process_extraction = <class 'pylena.pylena_cxx.scribo.e_segdet_process_extraction'>

Members:

BINARY : Binary extraction with threshold

GRADIENT : Gradient extraction with threshold

Classes

class pylena.scribo.VSegment
property label

Label of the segment

property x0

First coordinate of first point

property x1

First coordinate of second point

property y0

Second coordinate of first point

property y1

Second coordinate of second point

class pylena.scribo.LSuperposition
property label

Label of the line superposing

property x

First coordinate of the superposition

property y

Second coordinate of the superposition

Functions

pylena.scribo.line_detector(img: ndarray, mode: str = 'full', verbose: bool = False, **kwargs) List[VSegment] | Tuple[ndarray, List[LSuperposition]] | Tuple[ndarray, List[LSuperposition], List[VSegment]]

Perform a line detection in a greyscale document image from [7]

Parameters:
  • img (2-D array (dtype=uint8)) – The image to be processed

  • mode (str) – The mode of the line detection. Should be one of ‘full’, ‘pixel’ or ‘vector’

  • verbose (bool) – Whether to print information about the line detection

  • **kwargs (Additional keyword arguments.)

  • Arguments (Keyword) –

    min_len (int, optional): The minimum length of a line.

    Default is 10.

    preprocess (e_segdet_preprocess, optional): Preprocess applied.

    Default is e_segdet_preprocess.NONE.

    tracker (e_segdet_process_tracking, optional): Tracker used.

    Default is e_segdet_process_tracking.KALMAN.

    traversal_mode (e_segdet_process_traversal_mode, optional): Traversal performed.

    Default is e_segdet_process_traversal_mode.HORIZONTAL_VERTICAL.

    extraction_type (e_segdet_process_extraction, optional): Extraction type for observations.

    Default is e_segdet_process_extraction.BINARY.

    negate_image (bool, optional): Specify if the image has to be reversed before processing.

    Default is False.

    dyn (float, optional): Dynamic when Black-Top-Hat preprocess is applied.

    Default is 0.6.

    size_mask (int, optional): Filter size when Black-Top-Hat preprocess is applied.

    Default is 11.

    double_exponential_alpha (float, optional): Alpha used in double exponential tracker if chosen.

    Default is 0.6.

    simple_moving_average_memory (float, optional): Memory used in simple moving average tracker if chosen.

    Default is 30.0.

    exponential_moving_average_memory (float, optional): Memory used in exponential moving average tracker if chosen.

    Default is 16.0.

    one_euro_beta (float, optional): Beta used in one euro tracker if chosen.

    Default is 0.007.

    one_euro_mincutoff (float, optional): Min cutoff used in one euro tracker if chosen.

    Default is 1.0.

    one_euro_dcutoff (float, optional): Dcutoff used in one euro tracker if chosen.

    Default is 1.0.

    bucket_size (int, optional): Bucket size during traversal.

    Default is 32.

    nb_values_to_keep (int, optional): Memory of tracker to compute variances for the matching.

    Default is 30.

    discontinuity_relative (int, optional): Percentage. Discontinuity = discontinuity_absolute +

    discontinuity_relative * current_segment_size. Default is 0.

    discontinuity_absolute (int, optional): Discontinuity = discontinuity_absolute +

    discontinuity_relative * current_segment_size. Default is 0.

    minimum_for_fusion (int, optional): Threshold to merge trackers following the same observation.

    Default is 15.

    default_sigma_position (int, optional): Position default variance value.

    Default is 2.

    default_sigma_thickness (int, optional): Thickness default variance value.

    Default is 2.

    default_sigma_luminosity (int, optional): Luminosity default variance value.

    Default is 57.

    min_nb_values_sigma (int, optional): Threshold to compute variance and not use default values.

    Default is 10.

    sigma_pos_min (float, optional): Minimum position variance value.

    Default is 1.0.

    sigma_thickness_min (float, optional): Minimum thickness variance value.

    Default is 0.64.

    sigma_luminosity_min (float, optional): Minimum luminosity variance value.

    Default is 13.0.

    gradient_threshold (int, optional): Gradient threshold when gradient preprocess is applied.

    Default is 30.

    llumi (int, optional): First threshold for observation ternary extraction.

    Default is 225.

    blumi (int, optional): Second threshold for observation ternary extraction.

    Default is 225.

    ratio_lum (float, optional): Ratio of kept luminosity in observation extraction.

    Default is 1.0.

    max_thickness (int, optional): Max allowed (vertical|horizontal) thickness of segment to detect.

    Default is 100.

    threshold_intersection (float, optional): Threshold for duplication removal.

    Default is 0.8.

    remove_duplicates (bool, optional): Specify if duplication removal has to be computed.

    Default is True.

Returns:

The detected lines in the image or the label map, the superpositions and the segments of the detected lines depending on the mode of the line detection (see mode).

Return type:

List[VSegment] or Tuple[np.ndarray, List[LSuperposition]] or Tuple[np.ndarray, List[LSuperposition], List[VSegment]]

Example

>>> from pylena.scribo import line_detector
>>> img = ...  # Get an image
>>> img_label, superpositions, lines = pln.scribo.line_detector(
...     img, "full", min_len=100, blumi=110, llumi=110, discontinuity_relative=5
... )