feat: implement layout preprocessing backend
Backend implementation for add-layout-preprocessing proposal:
- Add LayoutPreprocessingService with CLAHE, sharpen, binarize
- Add auto-detection: analyze_image_quality() for contrast/edge metrics
- Integrate preprocessing into OCR pipeline (analyze_layout)
- Add Preview API: POST /api/v2/tasks/{id}/preview/preprocessing
- Add config options: layout_preprocessing_mode, thresholds
- Add schemas: PreprocessingConfig, PreprocessingPreviewResponse
Preprocessing only affects layout detection input.
Original images preserved for element extraction.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -146,6 +146,39 @@ class Settings(BaseSettings):
|
||||
description="Formula recognition model. PP-FormulaNet_plus-L recommended for Chinese formula support."
|
||||
)
|
||||
|
||||
# ===== Layout Preprocessing Configuration =====
|
||||
# Image preprocessing to enhance layout detection for documents with faint lines/borders
|
||||
# Preprocessing only affects layout detection input; original image is preserved for extraction
|
||||
layout_preprocessing_mode: str = Field(
|
||||
default="auto",
|
||||
description="Preprocessing mode: 'auto' (analyze and apply), 'manual' (use config), 'disabled'"
|
||||
)
|
||||
layout_preprocessing_contrast: str = Field(
|
||||
default="clahe",
|
||||
description="Contrast enhancement method: 'none', 'histogram', 'clahe' (recommended)"
|
||||
)
|
||||
layout_preprocessing_sharpen: bool = Field(
|
||||
default=True,
|
||||
description="Enable sharpening to enhance faint lines and borders"
|
||||
)
|
||||
layout_preprocessing_binarize: bool = Field(
|
||||
default=False,
|
||||
description="Enable binarization (aggressive, use for very low contrast documents only)"
|
||||
)
|
||||
# Auto-detection thresholds
|
||||
layout_preprocessing_contrast_threshold: float = Field(
|
||||
default=40.0,
|
||||
description="Contrast (std dev) below this triggers CLAHE in auto mode"
|
||||
)
|
||||
layout_preprocessing_edge_threshold: float = Field(
|
||||
default=15.0,
|
||||
description="Edge strength below this triggers sharpening in auto mode"
|
||||
)
|
||||
layout_preprocessing_binarize_threshold: float = Field(
|
||||
default=20.0,
|
||||
description="Contrast below this triggers binarization in auto mode"
|
||||
)
|
||||
|
||||
# ===== Gap Filling Configuration =====
|
||||
# Supplements PP-StructureV3 output with raw OCR regions when detection is incomplete
|
||||
gap_filling_enabled: bool = Field(default=True) # Enable gap filling for OCR track
|
||||
|
||||
Reference in New Issue
Block a user