Files
OCR/openspec/changes/add-layout-preprocessing/specs/ocr-processing/spec.md
egg c12ea0b9f6 proposal: add-layout-preprocessing for improved table detection
Problem: PP-Structure misses tables with faint lines/borders
Solution: Preprocess images (contrast, sharpen) for layout detection
- Preprocessed image only used for layout detection
- Original image preserved for element extraction (quality)

Includes: proposal.md, design.md, tasks.md, spec delta

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 14:24:23 +08:00

2.6 KiB

ADDED Requirements

Requirement: Layout Detection Image Preprocessing

The system SHALL provide optional image preprocessing to enhance layout detection accuracy for documents with faint lines, low contrast, or poor scan quality.

Scenario: Preprocessing improves table detection

  • GIVEN a document with faint table borders that PP-Structure fails to detect
  • WHEN layout preprocessing is enabled
  • THEN the system SHALL preprocess the image before layout detection
  • AND contrast enhancement SHALL make faint lines more visible
  • AND PP-Structure SHALL receive the preprocessed image for layout detection

Scenario: Image element extraction uses original quality

  • GIVEN an image element detected by PP-Structure from preprocessed input
  • WHEN the system extracts the image element
  • THEN the system SHALL crop from the ORIGINAL image, not the preprocessed version
  • AND the extracted image SHALL maintain original quality and colors

Scenario: Preprocessing can be disabled

  • GIVEN layout_preprocessing_enabled is set to false in configuration
  • WHEN OCR track processing runs
  • THEN the system SHALL skip preprocessing
  • AND PP-Structure SHALL receive the original image directly

Scenario: CLAHE contrast enhancement

  • WHEN layout_preprocessing_contrast is set to "clahe"
  • THEN the system SHALL apply Contrast Limited Adaptive Histogram Equalization
  • AND the enhancement SHALL not over-saturate already bright regions

Scenario: Sharpening enhances faint lines

  • WHEN layout_preprocessing_sharpen is enabled
  • THEN the system SHALL apply unsharp masking to enhance edges
  • AND faint table borders SHALL become more detectable

Scenario: Optional binarization for extreme cases

  • WHEN layout_preprocessing_binarize is enabled
  • THEN the system SHALL apply adaptive thresholding
  • AND this SHALL be used only for documents with very poor contrast

Requirement: Preprocessing Track Isolation

The layout preprocessing feature SHALL only affect layout detection input without impacting other processing components.

Scenario: Raw OCR is unaffected

  • GIVEN layout preprocessing is enabled
  • WHEN Raw OCR processing runs
  • THEN Raw OCR SHALL use the original image
  • AND text detection quality SHALL not be affected by preprocessing

Scenario: Preprocessed image is temporary

  • GIVEN an image is preprocessed for layout detection
  • WHEN layout detection completes
  • THEN the preprocessed image SHALL NOT be persisted to storage
  • AND only the original image and element crops SHALL be saved