Skip to main content

SegtFormats: a toolbox for minimalistic segmentation metadata.

SegtFormat allows for handling a subset of features found in common page layout formats (PAGE, ALTO) with a focus on HTR tasks:

  • 1 label document = 1 image = 1 page1
  • two types of objects only: regions (as bounding boxes) and lines (baselines and polygons)
  • conversion between common segmentation metadata formats (Page, ALTO).
  • custom JSON representation documented in our schema: the dictionary allows for easy structural transformations (flattening, region and/or line extraction) or for semantic transformations (line-to-region assignments, boundaries).
  • for metadata only: the image is not needed.
  • validation options (PAGE, JSON)
  • no fancy visuals: however a page segmentation can be conveniently rendered in ASCII on the terminal, for diagnosis purpose.

How to install

From GitHub:

git clone git@github.com:nicolasrenet/segtformats.git
cd segtformats
pip install .

From PyPi:

TBA

How to use

Library functions: examples

from segtformats import segtformats as sgf

# Alto to PageXML stream
page_xml_str = sgf.alto_to_page_xml('tests/data/217_d9c7f_default.alto.xml')

# Alto to PageXML file
sgf.alto_to_page_xml('tests/data/217_d9c7f_default.alto.xml', output_file='217_d9c7f_default.alto.page.xml')

# Alto to JSON dictionary
segmentation_dict = sgf.alto_to_segmentation_dict('tests/data/217_d9c7f_default.alto.xml')
# validation
assert sgf.json_validate( segmentation_dict )

# ASCII rendition
print(sgf.anyseg_to_ascii('tests/data/btv1b84473026_f25.chocomufin.xml', lines=1, scale_hw=.8))

Command-line utilities

  • alto_to_page_xml: Alto → Page conversion. Eg.

    alto_to_page_xml tests/data/217_d9c7f_default.alto.xml
    
  • alto_to_json: Alto → JSON conversion. Eg.

    alto_to_json tests/data/217_d9c7f_default.alto.xml
    
  • page_xml_to_json: Page → JSON conversion. Eg.

    page_xml_to_json tests/data/217_d9c7f_default.page.xml
    
  • anyseg_to_json: Detect input format and convert to JSON. Eg.

    anyseg_to_json --file_paths tests/data/*.xml
    
  • json_to_page_xml: JSON → Page conversion.

    json_to_page_xml tests/data/217_d9c7f_default.json
    
  • anyseg_doctor: Various transformations on JSON metadata, including repairs (region boundaries, line-to-region assignments).

    # diagnosis-only by default (dry run)
    anyseg_doctor tests/data/217_d9c7f_default.page.xml
    # repairing an ALTO file, with PAGE output
    anyseg_doctor --repair --output_format page --output_suffix .fixed.xml tests/data/217_d9c7f_default.alto.xml 
    
  • anyseg_to_ascii: Render segmentation metadata on the terminal. Eg.

    anyseg_to_ascii --file_paths tests/data/*.xml
    
  • page_xml_split: Split multi-page PAGE label into as many files (i.e. one label per image). Eg.

    page_xml_split --file_paths tests/data/2923.xml
    

Get the help on any <command> with

python3 -m segtformats.<command> -h

TODO:

  • Page → Alto
  1. Neither of the commonly used formats enforces the 1-1-1 cardinality: with PAGE, 1 document may label n images (each corresponding to exactly 1 Page element); in ALTO, 1 document labels exactly 1 image and possibly n pages within it. ↩

Metadata

Release files for segtformats 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for segtformats 0.3
File Size Uploaded Provenance Actions
segtformats-0.3.tar.gz 39.9 kB Without provenance Details for segtformats-0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for segtformats 0.3
File Interpreter ABI Platform Actions
segtformats-0.3-py3-none-any.whl Python 3 none any Details for segtformats-0.3-py3-none-any.whl

Total release size: 84.6 kB

Release files / segtformats-0.3.tar.gz

Download URL segtformats-0.3.tar.gz
Size 39.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ecf98cc73ec3c32ade2b1737e041220a5aa6ca36615195c83dc877da65723b0d
BLAKE2b-256 checksum
How to use checksums
773b43112ec818e311fbedcbbba7b176d1e815fc67d9f78882c9b29b0151536d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.14

Release files / segtformats-0.3-py3-none-any.whl

Download URL segtformats-0.3-py3-none-any.whl
Size 44.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
375414dbab6fae00d7f9d261f06f39408a53dbc9314686a00be7e2ebacc1e5f5
BLAKE2b-256 checksum
How to use checksums
3e26889d1d82aeb59fa8853eeecebe6ee81f4afe2016c6ae399250c11ad97bfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.14

Security for segtformats 0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page