ML Pipeline & Inpainting Engine
Architectural breakdown of text detection, multilingual OCR reading flow, LaMa neural inpainting, and typesetting.
Preview Content
Please note that the details on this page are pre-content drafts. More detailed technical specifications, architectural breakdowns, and updated guides will be added soon.
1. The 6-Stage Neural Architecture
XianScan executes a modular, multi-threaded neural pipeline implemented directly in native Rust:
text
[Raw Webtoon Strip / Comic Page]
│
▼
1. Webtoon Gutter Reslicing (src/ml/reslice.rs)
│ ── Detects non-text whitespace valleys and avoids slicing panels/bubbles
▼
2. Bubble & Text Line Detection (src/ml/detect/)
│ ── Koharu RF-DETR Seg 2XL & DBNet extract oriented polygon contours
▼
3. Multi-Script OCR & Reading Flow Fusion (src/ml/ocr/ & src/pipeline/fusion.rs)
│ ── RapidOCR (10 languages) with cultural flow sorting (RTL Manga / LTR Webtoons)
▼
4. Context-Aware LLM Translation & Glossaries (web/src/lib/server/translate/)
│ ── 5-page sliding dialogue tracker + Aho-Corasick multilingual domain dictionaries
▼
5. Neural Background Inpainting (src/ml/inpaint/)
│ ── 1:1 localized patch cropping with LaMa Fast Fourier Convolutions (FFC)
▼
6. Automated Typography & Typesetting (web/src/lib/server/typeset/)
│ ── Google Skia binary-search font sizing, outline strokes, and bubble tilt
▼
[Cleaned & Typeset Comic Canvas]
2. Speech Bubble Detection & Spatial Region Building
- Koharu RF-DETR Seg 2XL (
src/ml/detect/rfdetr.rs): High-resolution transformer segmentation model that outputs exact polygon boundaries for oval speech bubbles, jagged scream bubbles, and rectangular narrative caption boxes. - DBNet Polygon Extraction (
src/ml/detect/dbnet.rs): Differentiable Binarization text detector capturing fine-grained character bounding coordinates and orientation angles. - Spatial Clustering & Deduplication (
src/pipeline/region_builder/): clustering.rs: Aggregates overlapping or adjacent text lines into coherent dialogue blocks.expansion.rs: Expands text bounding boxes with configurable safety padding to ensure full glyph coverage.dedup.rs: Resolves conflicting bounding boxes using Intersection-over-Union (IoU) heuristics.
3. Multi-Language OCR & Cultural Reading Flow
- RapidOCR PP-OCRv6 Engine (
src/ml/ocr/engine.rs): Embedded multi-lingual OCR pipeline supporting 10 languages: - Chinese (Simplified & Traditional), Japanese (Kanji, Hiragana, Katakana), Korean (Hangul), Thai, Indonesian, English, Spanish, French, Russian.
- Cultural Reading Flow Sorter (
src/ml/detect/grouping.rs&src/pipeline/fusion.rs): - Japanese Manga: Right-to-Left (RTL) reading flow. Iterates vertical text columns from right to left within horizontal narrative bands.
- Korean Manhwa & Chinese Manhua: Top-to-Bottom vertical flow with left-to-right reading hierarchy.
4. LaMa Neural Inpainting & 1:1 Local Patching
- Large Mask Inpainting (LaMa) Architecture (
src/ml/inpaint/lama.rs): Utilizes Fast Fourier Convolutions (FFC) with global receptive fields to reconstruct complex background textures, screentone patterns, and gradients. - 1:1 Localized Patch Cropping Engine (
src/ml/inpaint/patch.rs): - Traditional inpainting tools downscale entire 4K comic canvases to 512x512, causing severe blurriness across the whole page.
- XianScan crops tight local patches around detected dialogue bubbles, inpaints each patch at native resolution, and composites them back seamlessly onto the unedited source image.
- Solid Background Fast Path (
is_solid_background_patch): - Automatically identifies solid / flat white speech bubbles and replaces them instantly with exact color fills, bypassing GPU neural execution for sub-millisecond performance.
5. Automated Typesetting & Typography Studio
- Google Skia Canvas Engine (
@napi-rs/canvas): Native high-performance 2D graphics rendering embedded directly in the server. - Binary Search Font Sizing (
web/src/lib/server/typeset/layout.ts): Dynamically computes the maximum legible font size that fits comfortably within the speech bubble's polygon mask. - Multi-Line Text Wrapping & Hyphenation: Balances line lengths to prevent orphan words and maintain aesthetic dialogue shapes.
- Outline Strokes & Bubble Tilt: Applies configurable contrast outline strokes and rotates text lines to match the orientation angle of tilted dialogue bubbles.