Conversation
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is moved to ssciwr/ecpo_ocrd#2
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)