modules¶
geometor.pacioli¶
Tools for parsing and processing “De Divina Proportione” by Luca Pacioli.
Key Components:¶
Parser: The
PacioliParserclass extracts chapters and content from the transcribed text.Execution: The run_parse.py script executes the parsing process.
Usage:¶
Initialize PacioliParser with resources and output directories, then call parse().
Submodules¶
Classes¶
Functions¶
|
Extract page images and text for the entire volume in parallel. |
|
Compile all per-folio <folio>.json files into graphics_index.json. |
|
Normalize aged parchment background and binding shadows to pure white (255). |
|
Detect full-page plate graphics using OpenCV if available, falling back to SciPy. |
|
Detect woodcut illuminated initial caps by finding 2D ink-density centers along the text column edge. |
|
Detect geometric diagrams and marginalia strictly in the outer margin of a text folio. |
|
Extract all margin graphics and illuminated initial caps defined in <folio>.json. |
Package Contents¶
- class geometor.pacioli.PacioliParser(resources_dir: pathlib.Path, output_dir: pathlib.Path)¶
- resources_dir¶
- output_dir¶
- transcribed_file¶
- parse()¶
Execute the parsing process.
This method orchestrates the extraction of TOC and text chapters, merges them, and generates the RST output structure.
- extract_chapters(lines: List[str], start_marker: str, end_marker: str, prefix: str) Dict[str, Dict]¶
Extract chapters from a section of lines.
- Parameters:
lines – The list of lines to process.
start_marker – The string marking the start of the section.
end_marker – The string marking the end of the section.
prefix – The prefix for chapter headers (e.g., “Cap”, “Gap”).
- Returns:
A dictionary of chapters keyed by Roman Numeral ID.
- Return type:
- merge_chapters(toc_chapters: Dict, text_chapters: Dict) List[Dict]¶
Merge TOC and Text chapters into a single list.
- Parameters:
toc_chapters – Dictionary of chapters extracted from the TOC.
text_chapters – Dictionary of chapters extracted from the text.
- Returns:
A list of merged chapter dictionaries, sorted by Roman Numeral ID.
- Return type:
- generate_rst_structure(chapters: List[Dict], output_dir: pathlib.Path)¶
Generate the RST folder structure and files for the chapters.
- Parameters:
chapters – List of chapter dictionaries.
output_dir – The directory where RST files will be generated.
- create_main_index(chapters: List[Dict], output_dir: pathlib.Path)¶
- create_chapter_files(chapter_dir: pathlib.Path, chapter: Dict)¶
- geometor.pacioli.extract_all(pdf_path: pathlib.Path, output_dir: pathlib.Path, start_page: int = 1, end_page: int = 318, dpi: int = 150, max_workers: int = 6, force: bool = False) None¶
Extract page images and text for the entire volume in parallel.
- geometor.pacioli.build_graphics_index(directory: pathlib.Path) pathlib.Path¶
Compile all per-folio <folio>.json files into graphics_index.json.
- geometor.pacioli.clean_image(pil_image: PIL.Image.Image, white_point: int = 226, preserve_color: bool = False) PIL.Image.Image¶
Normalize aged parchment background and binding shadows to pure white (255).
Uses morphological closing + Gaussian blur to estimate local paper illumination per channel, eliminating yellowed paper cast, bleed-through, and gutter shadows while preserving crisp ink. When
preserve_color=True(e.g., red rubrication on folios 0005 and 0311), chromatic ink is kept.
- geometor.pacioli.detect_graphics_cv(image_path: pathlib.Path) List[Dict[str, Any]]¶
Detect full-page plate graphics using OpenCV if available, falling back to SciPy.
- geometor.pacioli.detect_initials(image_path: pathlib.Path) List[Dict[str, Any]]¶
Detect woodcut illuminated initial caps by finding 2D ink-density centers along the text column edge.
Woodcut initials in the 1509 Paganini edition have consistent square dimensions: - Standard chapter initials: 120x132 px (padded around the ~112x118 woodcut frame) - Large treatise-opening initials (folios 0017 and 0085): 260x304 px - Title-page red initial D (folio 0005): 184x188 px
- geometor.pacioli.detect_margin_figures(image_path: pathlib.Path, is_recto: bool) List[Dict[str, Any]]¶
Detect geometric diagrams and marginalia strictly in the outer margin of a text folio.
Odd (recto) folios: right outer margin (to the right of the main text column).
Even (verso) folios: left outer margin (to the left of the main text column).
Never falls back to full-page text blocks.
- geometor.pacioli.extract_from_json(json_path: pathlib.Path, no_clean: bool = False) None¶
Extract all margin graphics and illuminated initial caps defined in <folio>.json.