Layouts

Supported layouts:

SimpleSorting

class manuscript.layouts.SimpleSorting(max_splits=10, use_columns=True)[source]

Bases: BaseLayout

Group detected words into lines and arrange text in reading order.

Parameters:
  • max_splits (int, optional) – Maximum number of column splits. Default is 10; zero uses the horizontal extent of the regions as the iteration limit.

  • use_columns (bool, optional) – Separate Page-level words into columns before grouping. Default is True.

Examples

>>> from manuscript.layouts import SimpleSorting
>>> layout = SimpleSorting(use_columns=False)
>>> page = layout.predict(page)

See also

ReadingSorting

Order detected regions and optionally infer containment.

predict(page, image=None)[source]

Group and sort regions in place.

Parameters:
  • page (Page) – Document tree to organize.

  • image (numpy.ndarray, optional) – Accepted for Pipeline compatibility; not used.

Returns:

The supplied Page with updated grouping and child order.

Return type:

Page

ReadingSorting

class manuscript.layouts.ReadingSorting(mode='sort', containment_overlap=0.5, row_overlap=0.5, infer_columns=True)[source]

Bases: BaseLayout

Arrange detected regions in reading order and optionally nest them.

Parameters:
  • mode ({"sort", "containment"}, optional) – “sort” changes child order while retaining parent links. “containment” also assigns Page-level regions to detected lines and blocks. Default is “sort”.

  • containment_overlap (float, optional) – Minimum intersection area divided by the child’s polygon area for assigning a parent. Must be in (0, 1]; default is 0.5.

  • row_overlap (float, optional) – Minimum vertical overlap divided by the smaller bounding-box height for regions to share a reading row. Must be in (0, 1]; default is 0.5.

  • infer_columns (bool, optional) – Use horizontal whitespace gaps to order columns left to right. Default is True. In containment mode, also create column blocks when the input has no Page-level text blocks.

Examples

>>> from manuscript.layouts import ReadingSorting
>>> layout = ReadingSorting(mode="containment", containment_overlap=0.5)
>>> page = layout.predict(page)

See also

SimpleSorting

Create lines and blocks from detected words.

predict(page, image=None)[source]

Organize the document tree in place.

Parameters:
  • page (Page) – Document tree to organize.

  • image (optional) – Accepted for Pipeline compatibility; not used.

Returns:

The supplied Page with updated child order and, in containment mode, inferred parent links and optional column blocks.

Return type:

Page