-
Notifications
You must be signed in to change notification settings - Fork 0
Split image into page segments #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a page splitting algorithm that uses PaddleOCR and Dynamic Programming to detect gutters and split multi-page scanned images into individual page segments.
Key changes:
- Implements a CLI-based page splitting script using PaddleOCR for text detection and ruptures library for breakpoint detection via Dynamic Programming
- Adds configuration management system with JSON schema validation
- Provides comprehensive test coverage for utility functions and configuration handling
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| ecpo_eynollah/split_pages.py | Main splitting algorithm with OCR-based gutter detection and Dynamic Programming for finding split points |
| ecpo_eynollah/config_handler.py | Configuration loading, validation, and saving utilities with schema-based validation |
| ecpo_eynollah/utils.py | Image I/O utilities and unique tag generation for output files |
| ecpo_eynollah/config/default_config.json | Default configuration with gutter detection parameters |
| ecpo_eynollah/config/config_schema.json | JSON schema for validating configuration structure and values |
| tests/test_utils.py | Test coverage for utility functions including image operations and tag generation |
| tests/test_config_handler.py | Comprehensive tests for configuration validation, loading, and updating |
| tests/conftest.py | Test helper function for file retrieval |
| tests/test_ecpo_eynollah.py | Removed placeholder test file |
| pyproject.toml | Added dependencies for PaddleOCR, OpenCV, ruptures, and JSON schema validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Split strategy
For each input image:
2.1) based on the text detection result to mask text areas, masked areas are white, background is black
2.2) compute column-wise projection on the masked image, i.e. mean of pixel values per column (signal)
3.1) use Dynamic Programming to find vertical breakpoints of significant gaps
3.2) find refined points between those breakpoints that their signal near zero (black), i.e. no text there
3.3) only consider points near the center to ensure we have num_segments - 1 splits
In case the imge is completely skewed, I would suggest we have an extra step for preprocessing before any other steps.
Tasks
split_pages.py)config_handler.py)utils.py)notebooks/page_splitting.ipynb)Usage
The script can run with command line:
python split_pages.py [-c config_file.json -t "unique_tag"]If config file and tag are not specified, use default values:
ecpo_eynollah/config/default_config.jsonts{YYYYMMDD-HHMMSS}_h{hostname}Note on results
{img_name}_p{i}_{unique_tag}.jpgNote on choosing config values
"num_segments"and"close_threshold""num_segments"in the config should be 5, i.e. left page - small gap before gutter - gutter - small gap after gutter - right page. These small gaps will be omitted while splitting.Jingbao images: (corresponding config files are uploaded)
Data overview
Current results
num_segments=5, we can successfully separate the gutters in some images. However, the remaining cases are incorrect: the gutter is grouped with one side, while the opposite side is split into 2 parts.num_segments=3, which produces 2 main segments, with the gutter included on one side.jb_3796_1939-04-22_0006to0007.png. To correct this, change theclose_thresholdto 3 (see last section in the demo notebook)