Mayo commited on
Commit
09357e4
·
unverified ·
1 Parent(s): 2ab6c3c

docs: reflect new models

Browse files
README.md CHANGED
@@ -20,7 +20,7 @@ Under the hood, Koharu uses [candle](https://github.com/huggingface/candle) and
20
 
21
  ## Features
22
 
23
- - Automatic speech bubble detection and segmentation
24
  - OCR for manga text recognition
25
  - Inpainting to remove original text from images
26
  - LLM-powered translation
@@ -124,15 +124,22 @@ Koharu uses a mix of computer vision and language models rather than trying to s
124
 
125
  Koharu uses several pre-trained models for different parts of the pipeline:
126
 
127
- - [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors) for text detection and layout analysis
128
- - [comic-text-detector](https://huggingface.co/mayocream/comic-text-detector) for text segmentation
129
  - [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) for OCR text recognition
130
- - [lama-manga](https://huggingface.co/mayocream/lama-manga) for inpainting
131
  - [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection) for font and color detection
132
 
 
 
 
 
 
 
 
133
  The models are downloaded automatically when you run Koharu for the first time.
134
 
135
- We convert the upstream weights to safetensors format for better compatibility and runtime behavior in Rust. The converted weights are hosted on [Hugging Face](https://huggingface.co/mayocream).
136
 
137
  For a closer look at the pipeline, see [Models and Providers](https://koharu.rs/explanation/models-and-providers/) and the [Technical Deep Dive](https://koharu.rs/explanation/technical-deep-dive/).
138
 
 
20
 
21
  ## Features
22
 
23
+ - Automatic text block detection, speech bubble detection, and segmentation masks
24
  - OCR for manga text recognition
25
  - Inpainting to remove original text from images
26
  - LLM-powered translation
 
124
 
125
  Koharu uses several pre-trained models for different parts of the pipeline:
126
 
127
+ - [comic-text-bubble-detector](https://huggingface.co/ogkalu/comic-text-and-bubble-detector) for joint text block and speech bubble detection
128
+ - [comic-text-detector](https://huggingface.co/mayocream/comic-text-detector) for text segmentation masks
129
  - [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) for OCR text recognition
130
+ - [aot-inpainting](https://huggingface.co/mayocream/aot-inpainting) for default inpainting
131
  - [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection) for font and color detection
132
 
133
+ Optional built-in alternatives available in **Settings > Engines** include:
134
+
135
+ - [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors) as an alternative detector and layout-analysis engine
136
+ - [speech-bubble-segmentation](https://huggingface.co/mayocream/speech-bubble-segmentation) as a dedicated speech bubble detector
137
+ - [Manga OCR](https://huggingface.co/mayocream/manga-ocr) and [MIT 48px OCR](https://huggingface.co/mayocream/mit48px-ocr) as alternative OCR engines
138
+ - [lama-manga](https://huggingface.co/mayocream/lama-manga) as an alternative inpainter
139
+
140
  The models are downloaded automatically when you run Koharu for the first time.
141
 
142
+ Some models are consumed directly from upstream Hugging Face repos, while Rust-friendly safetensors conversions are hosted on [Hugging Face](https://huggingface.co/mayocream) when Koharu needs a converted bundle.
143
 
144
  For a closer look at the pipeline, see [Models and Providers](https://koharu.rs/explanation/models-and-providers/) and the [Technical Deep Dive](https://koharu.rs/explanation/technical-deep-dive/).
145
 
docs/en-US/explanation/how-koharu-works.md CHANGED
@@ -4,19 +4,20 @@ title: How Koharu Works
4
 
5
  # How Koharu Works
6
 
7
- Koharu is built around a page pipeline for manga translation. The user-facing workflow is simple, but the implementation intentionally separates layout, segmentation, OCR, inpainting, translation, and rendering into different stages.
8
 
9
  ## The pipeline at a glance
10
 
11
  ```mermaid
12
  flowchart LR
13
  A[Input manga page] --> B[Detect stage]
14
- B --> B1[Layout analysis]
15
  B --> B2[Segmentation mask]
16
  B --> B3[Font hints]
17
  B1 --> C[OCR stage]
18
  B2 --> D[Inpaint stage]
19
  C --> E[LLM translation stage]
 
20
  D --> F[Render stage]
21
  E --> F
22
  F --> G[Localized page or PSD export]
@@ -32,8 +33,8 @@ At the public pipeline level, Koharu runs:
32
 
33
  The important implementation detail is that `Detect` is already a multi-model stage:
34
 
35
- - `PP-DocLayoutV3` finds text-like layout regions and reading order.
36
- - `comic-text-detector` produces a per-pixel text probability map.
37
  - `YuzuMarker.FontDetection` estimates font and color hints for later rendering.
38
 
39
  That split is why Koharu can use one model to decide where text belongs on the page and another to decide which exact pixels should be removed.
@@ -42,9 +43,9 @@ That split is why Koharu can use one model to decide where text belongs on the p
42
 
43
  | Stage | Main models | Main output |
44
  | --- | --- | --- |
45
- | Detect | `PP-DocLayoutV3`, `comic-text-detector`, `YuzuMarker.FontDetection` | text blocks, segmentation mask, font hints |
46
  | OCR | `PaddleOCR-VL-1.5` | recognized source text for each block |
47
- | Inpaint | `lama-manga` | page with original text removed |
48
  | LLM Generate | local GGUF LLM or remote provider | translated text |
49
  | Render | Koharu renderer | final localized page or export |
50
 
@@ -57,20 +58,20 @@ Manga pages are harder than plain document OCR:
57
  - text can overlap artwork, screentones, speed lines, and panel borders
58
  - reading order is part of the page structure, not just the raw pixels
59
 
60
- Because of that, one model is usually not enough. Koharu first estimates layout, then runs OCR on cropped regions, then uses a segmentation mask for cleanup, and only then asks an LLM to translate the text.
61
 
62
  ## The implementation shape
63
 
64
- In source terms, the pipeline entrypoint runs in `koharu-app/src/pipeline.rs`, while the vision stack is coordinated in `koharu-app/src/ml.rs`.
65
 
66
  Some implementation details that matter:
67
 
68
- - the detect stage uses `PP-DocLayoutV3` first and converts text-like layout labels into `TextBlock` objects
69
- - overlapping boxes are deduplicated before OCR
70
- - text direction is inferred from region aspect ratio so vertical manga text can be handled earlier
71
  - OCR runs on cropped text regions, not on the full page
72
  - inpainting consumes the current segmentation mask, not just a rectangular box
73
  - when you choose a remote LLM provider, Koharu sends OCR text for translation, not the full page image
 
74
 
75
  ## Why the stack matters
76
 
@@ -92,6 +93,6 @@ If you configure a remote LLM provider, Koharu sends only the text selected for
92
 
93
  ## Want the deep technical version?
94
 
95
- See [Technical Deep Dive](technical-deep-dive.md) for model types, segmentation mask theory, FFT-based inpainting, and background references to Wikipedia diagrams plus official model cards. See [Text Rendering and Vertical CJK Layout](text-rendering-and-vertical-cjk-layout.md) for the renderer internals, vertical writing-mode behavior, and current layout limits.
96
 
97
 
 
4
 
5
  # How Koharu Works
6
 
7
+ Koharu is built around a page pipeline for manga translation. The user-facing workflow is simple, but the implementation intentionally separates joint detection, segmentation, OCR, inpainting, translation, and rendering into different stages.
8
 
9
  ## The pipeline at a glance
10
 
11
  ```mermaid
12
  flowchart LR
13
  A[Input manga page] --> B[Detect stage]
14
+ B --> B1[Text blocks and bubble regions]
15
  B --> B2[Segmentation mask]
16
  B --> B3[Font hints]
17
  B1 --> C[OCR stage]
18
  B2 --> D[Inpaint stage]
19
  C --> E[LLM translation stage]
20
+ B3 --> F
21
  D --> F[Render stage]
22
  E --> F
23
  F --> G[Localized page or PSD export]
 
33
 
34
  The important implementation detail is that `Detect` is already a multi-model stage:
35
 
36
+ - `comic-text-bubble-detector` finds text blocks and speech bubble regions.
37
+ - `comic-text-detector-seg` produces a per-pixel text probability map that becomes the cleanup mask.
38
  - `YuzuMarker.FontDetection` estimates font and color hints for later rendering.
39
 
40
  That split is why Koharu can use one model to decide where text belongs on the page and another to decide which exact pixels should be removed.
 
43
 
44
  | Stage | Main models | Main output |
45
  | --- | --- | --- |
46
+ | Detect | `comic-text-bubble-detector`, `comic-text-detector-seg`, `YuzuMarker.FontDetection` | text blocks, bubble regions, segmentation mask, font hints |
47
  | OCR | `PaddleOCR-VL-1.5` | recognized source text for each block |
48
+ | Inpaint | `aot-inpainting` | page with original text removed |
49
  | LLM Generate | local GGUF LLM or remote provider | translated text |
50
  | Render | Koharu renderer | final localized page or export |
51
 
 
58
  - text can overlap artwork, screentones, speed lines, and panel borders
59
  - reading order is part of the page structure, not just the raw pixels
60
 
61
+ Because of that, one model is usually not enough. Koharu first finds text blocks and bubble regions, then runs OCR on cropped regions, then uses a segmentation mask for cleanup, and only then asks an LLM to translate the text.
62
 
63
  ## The implementation shape
64
 
65
+ In source terms, the engine registry and pipeline execution live in `koharu-app/src/engine.rs`, while the default engine selection lives in `koharu-app/src/config.rs`.
66
 
67
  Some implementation details that matter:
68
 
69
+ - the default detect engine is `comic-text-bubble-detector`, which writes `TextBlock` values and bubble regions in one pass
70
+ - `comic-text-detector-seg` runs after text blocks exist and stores the final cleanup mask as `doc.segment`
 
71
  - OCR runs on cropped text regions, not on the full page
72
  - inpainting consumes the current segmentation mask, not just a rectangular box
73
  - when you choose a remote LLM provider, Koharu sends OCR text for translation, not the full page image
74
+ - individual stages can be swapped in **Settings > Engines** without changing the rest of the pipeline
75
 
76
  ## Why the stack matters
77
 
 
93
 
94
  ## Want the deep technical version?
95
 
96
+ See [Technical Deep Dive](technical-deep-dive.md) for model types, segmentation mask theory, AOT inpainting, and background references to official model cards. See [Text Rendering and Vertical CJK Layout](text-rendering-and-vertical-cjk-layout.md) for the renderer internals, vertical writing-mode behavior, and current layout limits.
97
 
98
 
docs/en-US/explanation/models-and-providers.md CHANGED
@@ -12,33 +12,42 @@ If you want the architecture-level explanation of how these pieces fit together,
12
 
13
  Koharu automatically downloads the required vision models when you use them for the first time.
14
 
15
- The default stack includes:
16
 
17
- - [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors) for text detection and layout analysis
18
- - [comic-text-detector](https://huggingface.co/mayocream/comic-text-detector) for text segmentation
19
  - [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) for OCR text recognition
20
- - [lama-manga](https://huggingface.co/mayocream/lama-manga) for inpainting
21
  - [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection) for font and color detection
22
 
23
- Converted model weights are hosted on [Hugging Face](https://huggingface.co/mayocream) in safetensors format for Rust compatibility and performance.
24
 
25
  ### What each vision model is
26
 
27
  | Model | Model type | Why Koharu uses it |
28
  | --- | --- | --- |
29
- | `PP-DocLayoutV3` | layout detector | finds text-like regions and reading order |
30
  | `comic-text-detector` | segmentation network | produces a text mask for cleanup |
31
  | `PaddleOCR-VL-1.5` | vision-language model | reads cropped text into text tokens |
32
- | `lama-manga` | inpainting network | reconstructs the image after text removal |
33
  | `YuzuMarker.FontDetection` | classifier / regressor | estimates font and style hints for rendering |
34
 
35
- The important design choice is that Koharu does not use a single model for every page task. Layout, segmentation, OCR, and inpainting all need different output shapes:
36
 
37
- - layout wants regions and order
38
  - segmentation wants per-pixel masks
39
  - OCR wants text
40
  - inpainting wants restored pixels
41
 
 
 
 
 
 
 
 
 
 
42
  ## Local LLMs
43
 
44
  Koharu supports local GGUF models through [llama.cpp](https://github.com/ggml-org/llama.cpp). These models run on your machine and are downloaded on demand when you select them in the LLM picker.
 
12
 
13
  Koharu automatically downloads the required vision models when you use them for the first time.
14
 
15
+ The current default stack includes:
16
 
17
+ - [comic-text-bubble-detector](https://huggingface.co/ogkalu/comic-text-and-bubble-detector) for joint text-block and speech-bubble detection
18
+ - [comic-text-detector](https://huggingface.co/mayocream/comic-text-detector) for text segmentation masks
19
  - [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) for OCR text recognition
20
+ - [aot-inpainting](https://huggingface.co/mayocream/aot-inpainting) for default inpainting
21
  - [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection) for font and color detection
22
 
23
+ Some models are used directly from upstream Hugging Face repos, while converted safetensors weights are hosted on [Hugging Face](https://huggingface.co/mayocream) when Koharu needs a Rust-friendly bundle.
24
 
25
  ### What each vision model is
26
 
27
  | Model | Model type | Why Koharu uses it |
28
  | --- | --- | --- |
29
+ | `comic-text-bubble-detector` | object detector | finds text blocks and speech bubble regions in one pass |
30
  | `comic-text-detector` | segmentation network | produces a text mask for cleanup |
31
  | `PaddleOCR-VL-1.5` | vision-language model | reads cropped text into text tokens |
32
+ | `aot-inpainting` | inpainting network | reconstructs masked image regions after text removal |
33
  | `YuzuMarker.FontDetection` | classifier / regressor | estimates font and style hints for rendering |
34
 
35
+ The important design choice is that Koharu does not use a single model for every page task. Detection, segmentation, OCR, and inpainting all need different output shapes:
36
 
37
+ - joint detection wants text blocks and bubble regions
38
  - segmentation wants per-pixel masks
39
  - OCR wants text
40
  - inpainting wants restored pixels
41
 
42
+ ### Optional built-in alternatives
43
+
44
+ You can swap individual stages in **Settings > Engines**. Built-in alternatives include:
45
+
46
+ - [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors) as an alternative detector and layout-analysis engine
47
+ - [speech-bubble-segmentation](https://huggingface.co/mayocream/speech-bubble-segmentation) as a dedicated bubble detector
48
+ - [Manga OCR](https://huggingface.co/mayocream/manga-ocr) and [MIT 48px OCR](https://huggingface.co/mayocream/mit48px-ocr) as alternative OCR engines
49
+ - [lama-manga](https://huggingface.co/mayocream/lama-manga) as an alternative inpainter
50
+
51
  ## Local LLMs
52
 
53
  Koharu supports local GGUF models through [llama.cpp](https://github.com/ggml-org/llama.cpp). These models run on your machine and are downloaded on demand when you select them in the LLM picker.
docs/en-US/explanation/technical-deep-dive.md CHANGED
@@ -4,19 +4,20 @@ title: Technical Deep Dive
4
 
5
  # Technical Deep Dive
6
 
7
- This page explains the technical side of Koharu's manga pipeline: what each model does, how the stages fit together, and why layout analysis, segmentation masks, OCR, inpainting, and translation are handled separately.
8
 
9
  ## The page pipeline in implementation terms
10
 
11
  ```mermaid
12
  flowchart TD
13
- A[Input page] --> B[PP-DocLayoutV3]
14
- A --> C[comic-text-detector]
15
- B --> D[Text blocks]
16
  C --> E[Segmentation mask]
17
  A --> F[YuzuMarker font detector]
 
18
  D --> G[PaddleOCR-VL crop OCR]
19
- E --> H[LaMa inpainting]
20
  G --> I[Local or remote LLM]
21
  F --> J[Renderer style hints]
22
  H --> K[Renderer]
@@ -27,7 +28,7 @@ flowchart TD
27
 
28
  At the code level, the public pipeline steps are `Detect -> OCR -> Inpaint -> LLM Generate -> Render`, but the detect stage is already doing three distinct jobs:
29
 
30
- - page layout analysis
31
  - text foreground segmentation
32
  - font and color estimation
33
 
@@ -37,22 +38,24 @@ That design is deliberate. A manga translation tool needs both page structure an
37
 
38
  | Component | Default model | Model type | Main job in Koharu |
39
  | --- | --- | --- | --- |
40
- | Layout analysis | [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors) | document layout detector | find text-like regions, labels, confidence, and reading order |
41
  | Segmentation | [comic-text-detector](https://github.com/dmMaze/comic-text-detector) | text segmentation network | produce a dense text mask for cleanup |
42
  | OCR | [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) | vision-language model | read cropped text regions into Unicode text |
43
- | Inpainting | [lama-manga](https://huggingface.co/mayocream/lama-manga) / [LaMa](https://github.com/advimman/lama) | image inpainting network | fill masked regions after text removal |
44
  | Font hints | [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection) | image classifier / regressor | estimate font family, colors, and stroke hints |
45
  | Translation | local GGUF model via [llama.cpp](https://github.com/ggml-org/llama.cpp) or remote API | decoder-only LLM in most local setups | translate OCR text into the target language |
46
 
47
- ## Why layout analysis matters on manga pages
48
 
49
- Layout analysis is not just "find boxes around text". On manga pages it has to answer several structural questions:
 
 
50
 
51
  - which regions are text-like at all
52
- - where the reading order probably is
53
  - whether a block is tall enough to behave like vertical text
54
  - which boxes should be deduplicated before OCR
55
- - which parts of the page are captions, bubble text, titles, or other layout categories
56
 
57
  This matters because manga is visually dense:
58
 
@@ -61,17 +64,16 @@ This matters because manga is visually dense:
61
  - vertical Japanese and horizontal Latin text can coexist on the same page
62
  - the region that should be read is not always the same shape as the pixels that should be erased
63
 
64
- Koharu uses layout output to create `TextBlock` records first, then uses those blocks to drive OCR and later rendering.
65
 
66
- In the current implementation, the layout stage:
67
 
68
- - runs `PP-DocLayoutV3::inference_one_fast(...)`
69
- - keeps regions whose labels look text-like
70
- - converts them into `TextBlock` values
71
- - deduplicates heavily overlapping regions
72
- - infers vertical vs horizontal source direction from aspect ratio
73
 
74
- So layout analysis is the structural backbone of the rest of the pipeline.
75
 
76
  ## What a segmentation mask is
77
 
@@ -96,24 +98,22 @@ flowchart LR
96
  In Koharu, the segmentation path is intentionally separate from layout:
97
 
98
  - `comic-text-detector` produces a grayscale probability map
99
- - Koharu refines that map with post-processing
100
- - the refined result becomes `doc.segment`
101
- - LaMa then uses `doc.segment` as the erase and fill mask for inpainting
102
 
103
- The refinement step matters because raw segmentation probabilities are usually soft and noisy. Koharu thresholds the prediction, tries block-aware refinement, and dilates the final binary mask so the cleanup covers text edges and outlines instead of leaving halos behind.
104
 
105
  ## How the vision models work in theory
106
 
107
- ### Layout analysis: detector plus reading-order reasoning
108
-
109
- [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3) is a layout model built for document parsing under skew, warping, and other non-planar distortions. Its model card highlights two properties that are especially relevant to manga-style pages:
110
 
111
- - it predicts multi-point geometry instead of only axis-aligned two-point boxes
112
- - it predicts logical reading order in the same forward pass
113
 
114
- Koharu's Rust port mirrors that shape: the `pp_doclayout_v3` module contains an `HGNetV2` backbone plus attention-based encoder and decoder blocks, and the inference result exposes `label`, `score`, `bbox`, `polygon_points`, and `order`.
 
115
 
116
- Conceptually, this is closer to object detection plus layout parsing than to OCR itself.
117
 
118
  ### Segmentation: dense per-pixel text prediction
119
 
@@ -123,9 +123,9 @@ Koharu's `comic-text-detector` path is a segmentation-first design. The Rust por
123
  - a U-Net decoder for mask prediction
124
  - an optional DBNet head for full detection mode
125
 
126
- The default page pipeline uses the segmentation-only path because Koharu already gets layout boxes from `PP-DocLayoutV3`. That means Koharu combines:
127
 
128
- - one model that is good at page structure
129
  - one model that is good at pixel-level text foreground
130
 
131
  This is a better fit for cleanup than relying on boxes alone.
@@ -152,34 +152,24 @@ Koharu's implementation follows that pattern closely:
152
 
153
  So OCR in Koharu is not a classic CTC-only recognizer. It is a small document-oriented VLM being used in a tightly scoped OCR task.
154
 
155
- ### Inpainting: why LaMa uses Fourier convolutions
156
 
157
- [LaMa](https://github.com/advimman/lama) is an inpainting model designed for large masked regions. Its paper title is explicit about the key idea: *Resolution-robust Large Mask Inpainting with Fourier Convolutions*.
158
 
159
  The important intuition is:
160
 
161
- - ordinary convolutions are local
162
- - text removal often needs long-range context from the rest of the bubble or background
163
- - frequency-domain operations can capture wider context efficiently
164
-
165
- This is where FFT comes in.
166
-
167
- #### What FFT means here
168
-
169
- FFT stands for **Fast Fourier Transform**. It is a fast algorithm for moving between:
170
 
171
- - the spatial domain, where pixels live
172
- - the frequency domain, where repeating patterns and large-scale structure are easier to manipulate
173
 
174
- In Koharu's LaMa port, the `FourierUnit` does exactly that:
 
 
 
175
 
176
- 1. apply `rfft2` to feature maps
177
- 2. process the real and imaginary channels with learned `1x1` convolutions
178
- 3. apply `irfft2` to return to image space
179
-
180
- Koharu even implements custom `rfft2` and `irfft2` ops for CPU, CUDA, and Metal backends so the same spectral block can run across hardware targets.
181
-
182
- For manga cleanup, this matters because the missing region is often not just a tiny scratch. It may be an entire speech bubble interior with gradients, screentones, and inked edges. Fourier-style global mixing helps the model preserve larger structures while filling the hole.
183
 
184
  ## Local LLMs and model type
185
 
@@ -203,21 +193,26 @@ Koharu keeps the image understanding steps local even when you choose a remote t
203
 
204
  Some details that are easy to miss if you only read the high-level docs:
205
 
206
- - the detect stage currently loads `ComicTextDetector::load_segmentation_only(...)`, not the full DBNet-backed detection mode
207
- - the segmentation mask is refined against the current detected text blocks before inpainting
 
208
  - OCR runs on cropped text-block images, not the original whole page
209
  - the OCR wrapper uses the multimodal llama.cpp path and the task prompt `OCR:`
210
  - inpainting consumes `doc.segment`, so bad masks lead directly to bad cleanup
 
211
  - font prediction is normalized before rendering so near-black and near-white colors snap to cleaner values
212
 
213
  ## Recommended reading
214
 
215
  ### Official model and project references
216
 
217
- - [PP-DocLayoutV3 model card](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3)
218
  - [PaddleOCR-VL-1.5 model card](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5)
219
  - [PaddleOCR-VL architecture docs in Hugging Face Transformers](https://huggingface.co/docs/transformers/en/model_doc/paddleocr_vl)
220
  - [comic-text-detector repository](https://github.com/dmMaze/comic-text-detector)
 
 
 
221
  - [LaMa repository](https://github.com/advimman/lama)
222
  - [llama.cpp](https://github.com/ggml-org/llama.cpp)
223
 
 
4
 
5
  # Technical Deep Dive
6
 
7
+ This page explains the technical side of Koharu's manga pipeline: what each model does, how the stages fit together, and why text and bubble detection, segmentation masks, OCR, inpainting, and translation are handled separately.
8
 
9
  ## The page pipeline in implementation terms
10
 
11
  ```mermaid
12
  flowchart TD
13
+ A[Input page] --> B[comic-text-bubble-detector]
14
+ A --> C[comic-text-detector-seg]
15
+ B --> D[Text blocks + bubbles]
16
  C --> E[Segmentation mask]
17
  A --> F[YuzuMarker font detector]
18
+ D --> C
19
  D --> G[PaddleOCR-VL crop OCR]
20
+ E --> H[AOT inpainting]
21
  G --> I[Local or remote LLM]
22
  F --> J[Renderer style hints]
23
  H --> K[Renderer]
 
28
 
29
  At the code level, the public pipeline steps are `Detect -> OCR -> Inpaint -> LLM Generate -> Render`, but the detect stage is already doing three distinct jobs:
30
 
31
+ - text and bubble detection
32
  - text foreground segmentation
33
  - font and color estimation
34
 
 
38
 
39
  | Component | Default model | Model type | Main job in Koharu |
40
  | --- | --- | --- | --- |
41
+ | Text and bubble detection | [comic-text-bubble-detector](https://huggingface.co/ogkalu/comic-text-and-bubble-detector) | object detector | find text blocks and speech bubble regions |
42
  | Segmentation | [comic-text-detector](https://github.com/dmMaze/comic-text-detector) | text segmentation network | produce a dense text mask for cleanup |
43
  | OCR | [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) | vision-language model | read cropped text regions into Unicode text |
44
+ | Inpainting | [aot-inpainting](https://huggingface.co/mayocream/aot-inpainting) / [manga-image-translator](https://github.com/zyddnys/manga-image-translator) | image inpainting network | fill masked regions after text removal |
45
  | Font hints | [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection) | image classifier / regressor | estimate font family, colors, and stroke hints |
46
  | Translation | local GGUF model via [llama.cpp](https://github.com/ggml-org/llama.cpp) or remote API | decoder-only LLM in most local setups | translate OCR text into the target language |
47
 
48
+ Optional built-in alternatives remain available. The main ones are [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors) as an alternative detector and layout-analysis engine, [speech-bubble-segmentation](https://huggingface.co/mayocream/speech-bubble-segmentation) as a dedicated bubble detector, and [lama-manga](https://huggingface.co/mayocream/lama-manga) as an alternative inpainter.
49
 
50
+ ## Why text and bubble detection matters on manga pages
51
+
52
+ Detection is not just "find boxes around text". On manga pages it has to answer several structural questions:
53
 
54
  - which regions are text-like at all
55
+ - where speech bubbles are
56
  - whether a block is tall enough to behave like vertical text
57
  - which boxes should be deduplicated before OCR
58
+ - which regions should become editable `TextBlock` records
59
 
60
  This matters because manga is visually dense:
61
 
 
64
  - vertical Japanese and horizontal Latin text can coexist on the same page
65
  - the region that should be read is not always the same shape as the pixels that should be erased
66
 
67
+ Koharu uses the detector output to create `TextBlock` records first, then uses those blocks to drive OCR and later rendering. Bubble regions are kept as separate geometry so the UI and later tooling can still reason about the speech-balloon area.
68
 
69
+ In the current implementation, the default detect stage:
70
 
71
+ - runs the Candle port of `ogkalu/comic-text-and-bubble-detector`
72
+ - converts text detections into `TextBlock` values
73
+ - converts bubble detections into `BubbleRegion` values
74
+ - sorts text blocks into manga reading order before OCR
 
75
 
76
+ If you prefer a document-layout-style detector, `PP-DocLayoutV3` is still available as an alternative engine. It is just no longer the default.
77
 
78
  ## What a segmentation mask is
79
 
 
98
  In Koharu, the segmentation path is intentionally separate from layout:
99
 
100
  - `comic-text-detector` produces a grayscale probability map
101
+ - Koharu thresholds and dilates that map with lightweight post-processing
102
+ - the resulting binary mask becomes `doc.segment`
103
+ - `aot-inpainting` then uses `doc.segment` as the erase and fill mask for inpainting
104
 
105
+ The cleanup step still matters because raw segmentation probabilities are usually soft and noisy. Koharu thresholds the prediction and dilates the final binary mask so the cleanup covers text edges and outlines instead of leaving halos behind.
106
 
107
  ## How the vision models work in theory
108
 
109
+ ### Joint detection: text blocks and bubble regions in one pass
 
 
110
 
111
+ [ogkalu/comic-text-and-bubble-detector](https://huggingface.co/ogkalu/comic-text-and-bubble-detector) is the default detector because it directly predicts the two region types the rest of the pipeline cares about most:
 
112
 
113
+ - text-like regions that should become `TextBlock`s
114
+ - speech-bubble regions that should stay available to the editor and downstream tooling
115
 
116
+ Koharu's Candle port maps those detections into document data structures and then sorts the text blocks into manga reading order before OCR. Conceptually, this is closer to page object detection than to OCR itself.
117
 
118
  ### Segmentation: dense per-pixel text prediction
119
 
 
123
  - a U-Net decoder for mask prediction
124
  - an optional DBNet head for full detection mode
125
 
126
+ The default page pipeline uses the segmentation-only path because Koharu already gets text blocks from `comic-text-bubble-detector`. That means Koharu combines:
127
 
128
+ - one model that is good at page-level region detection
129
  - one model that is good at pixel-level text foreground
130
 
131
  This is a better fit for cleanup than relying on boxes alone.
 
152
 
153
  So OCR in Koharu is not a classic CTC-only recognizer. It is a small document-oriented VLM being used in a tightly scoped OCR task.
154
 
155
+ ### Inpainting: why the default is now AOT
156
 
157
+ The default inpainter is the AOT model from [manga-image-translator](https://github.com/zyddnys/manga-image-translator), exposed in Koharu as `aot-inpainting`. It is a masked-image inpainting network built around gated convolutions and repeated context-mixing blocks with multiple dilation rates.
158
 
159
  The important intuition is:
160
 
161
+ - text removal needs more than a rectangular crop fill
162
+ - the model needs both local edge detail and wider context from the bubble or background
163
+ - repeated multi-dilation blocks are a practical way to mix that context without changing the rest of the pipeline contract
 
 
 
 
 
 
164
 
165
+ Koharu's Candle port follows the upstream inference shape closely:
 
166
 
167
+ 1. resize large pages down to a configurable max side
168
+ 2. pad the working image to a multiple-of-8 shape
169
+ 3. feed the masked RGB image plus a binary text mask into the network
170
+ 4. composite the predicted pixels back into the original image size
171
 
172
+ `lama-manga` is still available as an alternative engine if you want LaMa's Fourier-based behavior, but it is no longer the default.
 
 
 
 
 
 
173
 
174
  ## Local LLMs and model type
175
 
 
193
 
194
  Some details that are easy to miss if you only read the high-level docs:
195
 
196
+ - the default detect stage is `comic-text-bubble-detector`, not `PP-DocLayoutV3`
197
+ - `comic-text-detector-seg` still loads the segmentation-only `comic-text-detector` path for `doc.segment`
198
+ - the segmentation mask is currently built from thresholding plus dilation, not the older block-aware refinement path
199
  - OCR runs on cropped text-block images, not the original whole page
200
  - the OCR wrapper uses the multimodal llama.cpp path and the task prompt `OCR:`
201
  - inpainting consumes `doc.segment`, so bad masks lead directly to bad cleanup
202
+ - the default inpainter is `aot-inpainting`, while `lama-manga` remains selectable as an alternative
203
  - font prediction is normalized before rendering so near-black and near-white colors snap to cleaner values
204
 
205
  ## Recommended reading
206
 
207
  ### Official model and project references
208
 
209
+ - [comic-text-and-bubble-detector model card](https://huggingface.co/ogkalu/comic-text-and-bubble-detector)
210
  - [PaddleOCR-VL-1.5 model card](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5)
211
  - [PaddleOCR-VL architecture docs in Hugging Face Transformers](https://huggingface.co/docs/transformers/en/model_doc/paddleocr_vl)
212
  - [comic-text-detector repository](https://github.com/dmMaze/comic-text-detector)
213
+ - [manga-image-translator repository](https://github.com/zyddnys/manga-image-translator)
214
+ - [YuzuMarker.FontDetection model card](https://huggingface.co/fffonion/yuzumarker-font-detection)
215
+ - [PP-DocLayoutV3 model card](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3)
216
  - [LaMa repository](https://github.com/advimman/lama)
217
  - [llama.cpp](https://github.com/ggml-org/llama.cpp)
218
 
docs/en-US/index.md CHANGED
@@ -494,7 +494,7 @@ hide:
494
  </div>
495
  <div class="kh-download-hero">
496
  <a class="kh-download-button" href="https://github.com/mayocream/koharu/releases/latest">
497
- Download for Windows&nbsp;&nbsp;<span class="kh-download-button__version">0.40.1</span>
498
  </a>
499
  <div class="kh-download-hero__subtext">
500
  Koharu is free and open source.
 
494
  </div>
495
  <div class="kh-download-hero">
496
  <a class="kh-download-button" href="https://github.com/mayocream/koharu/releases/latest">
497
+ Download for Windows&nbsp;&nbsp;<span class="kh-download-button__version">0.42.1</span>
498
  </a>
499
  <div class="kh-download-hero__subtext">
500
  Koharu is free and open source.
docs/ja-JP/explanation/how-koharu-works.md CHANGED
@@ -4,19 +4,20 @@ title: Koharu の仕組み
4
 
5
  # Koharu の仕組み
6
 
7
- Koharu は、漫画翻訳のためのページパイプラインを中心に設計されています。ユーザーから見た操作はシンプルですが、実装ではレイアウト解析、segmentation、OCR、inpainting、翻訳、レンダリングを意図的に別段階に分けています。
8
 
9
  ## パイプラインの全体像
10
 
11
  ```mermaid
12
  flowchart LR
13
  A[Input manga page] --> B[Detect stage]
14
- B --> B1[Layout analysis]
15
  B --> B2[Segmentation mask]
16
  B --> B3[Font hints]
17
  B1 --> C[OCR stage]
18
  B2 --> D[Inpaint stage]
19
  C --> E[LLM translation stage]
 
20
  D --> F[Render stage]
21
  E --> F
22
  F --> G[Localized page or PSD export]
@@ -32,8 +33,8 @@ flowchart LR
32
 
33
  重要なのは、`Detect` がすでに複数モデルから成る段階だということです。
34
 
35
- - `PP-DocLayoutV3` はテキストらしいレイアウト領域と読み順を見つけます
36
- - `comic-text-detector` はピクセル単位のテキスト確率マップを作ります
37
  - `YuzuMarker.FontDetection` は後段のレンダリングに使うフォントや色のヒントを推定します
38
 
39
  この分割によって、Koharu は「ページ上のどこにテキストがあるか」を決めるモデルと、「どのピクセルを実際に消すべきか」を決めるモデルを分けて使えます。
@@ -42,9 +43,9 @@ flowchart LR
42
 
43
  | 段階 | 主なモデル | 主な出力 |
44
  | --- | --- | --- |
45
- | Detect | `PP-DocLayoutV3`, `comic-text-detector`, `YuzuMarker.FontDetection` | テキストブロック、segmentation mask、フォントヒント |
46
  | OCR | `PaddleOCR-VL-1.5` | 各ブロックの認識済み元テキスト |
47
- | Inpaint | `lama-manga` | 元の文字を消したページ |
48
  | LLM Generate | ローカル GGUF LLM またはリモートプロバイダ | 翻訳済みテキスト |
49
  | Render | Koharu renderer | 最終的なローカライズ済みページまたは export |
50
 
@@ -57,20 +58,20 @@ flowchart LR
57
  - テキストが作画、スクリーントーン、スピード線、コマ枠に重なる
58
  - 読み順は単なるピクセル情報ではなく、ページ構造そのものの一部
59
 
60
- そのため、1 つのモデルだけでは足りないことが多くなります。Koharu はまずレイアウトを推定し、次に切り出し領域へ OCR をかけ、segmentation mask を使ってクリーンアップし、その後で初めて LLM に翻訳を依頼します。
61
 
62
  ## 実装の形
63
 
64
- ソースコード上では、パイプラインの入口は `koharu-app/src/pipeline.rs` にあり、vision スタックの調整は `koharu-app/src/ml.rs` で行われています。
65
 
66
  実装上、重要な点は次の通りです。
67
 
68
- - detect 段階では先に `PP-DocLayoutV3` を走らせ、テキストらしいラベルを `TextBlock` に変換する
69
- - 重なりすぎた box は OCR 前に重複除去される
70
- - テキスト方向は領域の縦横比から推定され、縦書き漫画テキストを早い段階で扱える
71
- - OCR はページ全体ではなく、切り出したテキスト領域に対して実行される
72
- - inpainting は単なる矩形ではなく、現在の segmentation mask を使う
73
- - リモート LLM プロバイダを選んだ場合でも、送るのはページ画像ではなく OCR テキスト
74
 
75
  ## このスタックが重要な理由
76
 
@@ -92,6 +93,4 @@ Koharu は次を使っています。
92
 
93
  ## もっと技術寄りの説明が欲しい場合
94
 
95
- モデル種別、segmentation mask の理屈、FFT ベースの inpainting、Wikipedia 図表と公式 model card への参照を含む詳細説明は [技術的な詳細解説](technical-deep-dive.md) を参照してください。レンダラ内部、縦書き挙動、現在のレイアウト上の限界については [テキストレンダリングと縦書き CJK レイアウト](text-rendering-and-vertical-cjk-layout.md) にあります。
96
-
97
-
 
4
 
5
  # Koharu の仕組み
6
 
7
+ Koharu は、漫画翻訳のためのページパイプラインを中心に設計されています。ユーザーから見た操作はシンプルですが、実装では joint detection、segmentation、OCR、inpainting、翻訳、レンダリングを意図的に別段階に分けています。
8
 
9
  ## パイプラインの全体像
10
 
11
  ```mermaid
12
  flowchart LR
13
  A[Input manga page] --> B[Detect stage]
14
+ B --> B1[Text blocks and bubble regions]
15
  B --> B2[Segmentation mask]
16
  B --> B3[Font hints]
17
  B1 --> C[OCR stage]
18
  B2 --> D[Inpaint stage]
19
  C --> E[LLM translation stage]
20
+ B3 --> F
21
  D --> F[Render stage]
22
  E --> F
23
  F --> G[Localized page or PSD export]
 
33
 
34
  重要なのは、`Detect` がすでに複数モデルから成る段階だということです。
35
 
36
+ - `comic-text-bubble-detector` はテキストブロックと吹き出し領域を見つけます
37
+ - `comic-text-detector-seg` はクリーンアップ用の per-pixel mask を作ります
38
  - `YuzuMarker.FontDetection` は後段のレンダリングに使うフォントや色のヒントを推定します
39
 
40
  この分割によって、Koharu は「ページ上のどこにテキストがあるか」を決めるモデルと、「どのピクセルを実際に消すべきか」を決めるモデルを分けて使えます。
 
43
 
44
  | 段階 | 主なモデル | 主な出力 |
45
  | --- | --- | --- |
46
+ | Detect | `comic-text-bubble-detector`, `comic-text-detector-seg`, `YuzuMarker.FontDetection` | テキストブロック、吹き出し領域、segmentation mask、フォントヒント |
47
  | OCR | `PaddleOCR-VL-1.5` | 各ブロックの認識済み元テキスト |
48
+ | Inpaint | `aot-inpainting` | 元の文字を消したページ |
49
  | LLM Generate | ローカル GGUF LLM またはリモートプロバイダ | 翻訳済みテキスト |
50
  | Render | Koharu renderer | 最終的なローカライズ済みページまたは export |
51
 
 
58
  - テキストが作画、スクリーントーン、スピード線、コマ枠に重なる
59
  - 読み順は単なるピクセル情報ではなく、ページ構造そのものの一部
60
 
61
+ そのため、1 つのモデルだけでは足りないことが多くなります。Koharu はまずテキストブロックと吹き出しを見つけ、次に切り出し領域へ OCR をかけ、segmentation mask を使ってクリーンアップし、その後で LLM に翻訳を依頼します。
62
 
63
  ## 実装の形
64
 
65
+ ソースコード上では、エンジンの登録とパイプライン実行は `koharu-app/src/engine.rs` にあり、既定エンジンの選択は `koharu-app/src/config.rs` にあります。
66
 
67
  実装上、重要な点は次の通りです。
68
 
69
+ - 既定の detect エンジンは `comic-text-bubble-detector` で、1 回の推論で `TextBlock` と吹き出し領域を書き込みます
70
+ - `comic-text-detector-seg` は text block が揃った後に走り、最終 mask を `doc.segment` として保存します
71
+ - OCR はページ全体ではなく、切り出したテキスト領域に対して実行されます
72
+ - inpainting は単なる矩形で��なく、現在の segmentation mask を使います
73
+ - リモート LLM プロバイダを選んだ場合でも、送るのはページ画像ではなく OCR テキストです
74
+ - **Settings > Engines** では他の段階を差し替えても残りのパイプラインはそのまま使えます
75
 
76
  ## このスタックが重要な理由
77
 
 
93
 
94
  ## もっと技術寄りの説明が欲しい場合
95
 
96
+ モデル種別、segmentation mask の理屈、AOT inpainting、公式 model card への参照を含む詳しい説明は [技術的な詳細解説](technical-deep-dive.md) を参照してください。レンダラ内部、縦書き挙動、現在のレイアウト上の限界については [テキストレンダリングと縦書き CJK レイアウト](text-rendering-and-vertical-cjk-layout.md) にあります。
 
 
docs/ja-JP/explanation/models-and-providers.md CHANGED
@@ -4,41 +4,50 @@ title: モデルとプロバイダ
4
 
5
  # モデルとプロバイダ
6
 
7
- Koharu は vision モデルと language モデルの両方を使います。vision スタックはページを整え、language スタックは翻訳を担当します。
8
 
9
- これらがアーキテクチャ上どう組み合わさっているかを知りたい場合は、このページのあとに [技術的な詳細解説](technical-deep-dive.md) を読んでください。
10
 
11
  ## Vision モデル
12
 
13
  Koharu は、必要な vision モデルを初回利用時に自動でダウンロードします。
14
 
15
- 既定のスタックには次が含まれます。
16
 
17
- - テキスト検出とレイアウト解析用の [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors)
18
- - テキスト segmentation 用の [comic-text-detector](https://huggingface.co/mayocream/comic-text-detector)
19
  - OCR テキスト認識用の [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5)
20
- - inpainting 用の [lama-manga](https://huggingface.co/mayocream/lama-manga)
21
  - フォントと色検出用の [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection)
22
 
23
- 変換済みのモデル重みは、Rust での互換性と性能のために、[Hugging Face](https://huggingface.co/mayocream) 上で safetensors 形式で公開されています。
24
 
25
  ### 各 vision モデルの役割
26
 
27
  | モデル | モデル種別 | Koharu で使う理由 |
28
  | --- | --- | --- |
29
- | `PP-DocLayoutV3` | レイアウト検出器 | テキストらしい領域と読み順を見つける |
30
  | `comic-text-detector` | segmentation network | クリーンアップ用の text mask を作る |
31
  | `PaddleOCR-VL-1.5` | vision-language model | 切り出したテキストを文字列へ読む |
32
- | `lama-manga` | inpainting network | 文字除去後の画像を補完する |
33
  | `YuzuMarker.FontDetection` | classifier / regressor | レンダリング用のフォントやスタイルのヒントを推定する |
34
 
35
- 重要なのは、Koharu がページ上の全作業を 1 つのモデルに任せていないことです。レイアウト、segmentation、OCR、inpainting はそれぞれ出力形が異なります。
36
 
37
- - レイアウトが欲しいのは領域と順序
38
  - segmentation が欲しいのはピクセル単位の mask
39
  - OCR が欲しいのは文字列
40
  - inpainting が欲しいのは補完されたピクセル
41
 
 
 
 
 
 
 
 
 
 
42
  ## ローカル LLM
43
 
44
  Koharu は [llama.cpp](https://github.com/ggml-org/llama.cpp) を通じてローカル GGUF モデルをサポートします。これらのモデルは手元のマシンで動き、LLM ピッカーで選んだときに必要に応じてダウンロードされます。
 
4
 
5
  # モデルとプロバイダ
6
 
7
+ Koharu は vision モデルと language モデルの両方を使います。vision スタックがページを整え、language スタックが翻訳を担当します。
8
 
9
+ これらがアーキテクチャ上でどう組み合わさっているかを知りたい場合は、このページのあとに [技術的な詳細解説](technical-deep-dive.md) を読んでください。
10
 
11
  ## Vision モデル
12
 
13
  Koharu は、必要な vision モデルを初回利用時に自動でダウンロードします。
14
 
15
+ 現在の既定スタックには次が含まれます。
16
 
17
+ - テキストブロックと吹き出しを同時に検出する [comic-text-bubble-detector](https://huggingface.co/ogkalu/comic-text-and-bubble-detector)
18
+ - テキスト segmentation mask を作る [comic-text-detector](https://huggingface.co/mayocream/comic-text-detector)
19
  - OCR テキスト認識用の [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5)
20
+ - 既定の inpainting 用の [aot-inpainting](https://huggingface.co/mayocream/aot-inpainting)
21
  - フォントと色検出用の [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection)
22
 
23
+ 一部のモデルは upstream の Hugging Face リポジトリをそのまま使い、Rust で扱いやすい safetensors 変換が必要なものは [Hugging Face](https://huggingface.co/mayocream) で配布しています。
24
 
25
  ### 各 vision モデルの役割
26
 
27
  | モデル | モデル種別 | Koharu で使う理由 |
28
  | --- | --- | --- |
29
+ | `comic-text-bubble-detector` | object detector | テキストブロックと吹き出し領域を 1 回で見つける |
30
  | `comic-text-detector` | segmentation network | クリーンアップ用の text mask を作る |
31
  | `PaddleOCR-VL-1.5` | vision-language model | 切り出したテキストを文字列へ読む |
32
+ | `aot-inpainting` | inpainting network | 文字除去後の masked 領域を補完する |
33
  | `YuzuMarker.FontDetection` | classifier / regressor | レンダリング用のフォントやスタイルのヒントを推定する |
34
 
35
+ 重要なのは、Koharu がページ上の全作業を 1 つのモデルに任せていないことです。検出、segmentation、OCR、inpainting はそれぞれ欲しい出力が異なります。
36
 
37
+ - joint detection が欲しいのはテキストブロックと吹き出し領域
38
  - segmentation が欲しいのはピクセル単位の mask
39
  - OCR が欲しいのは文字列
40
  - inpainting が欲しいのは補完されたピクセル
41
 
42
+ ### 組み込みの代替エンジン
43
+
44
+ **Settings > Engines** では段階ごとにエンジンを差し替えられます。主な代替候補は次の通りです。
45
+
46
+ - 代替の検出 / レイアウト解析エンジンとしての [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors)
47
+ - 専用の吹き出し検出エンジンとしての [speech-bubble-segmentation](https://huggingface.co/mayocream/speech-bubble-segmentation)
48
+ - 代替 OCR としての [Manga OCR](https://huggingface.co/mayocream/manga-ocr) と [MIT 48px OCR](https://huggingface.co/mayocream/mit48px-ocr)
49
+ - 代替 inpainter としての [lama-manga](https://huggingface.co/mayocream/lama-manga)
50
+
51
  ## ローカル LLM
52
 
53
  Koharu は [llama.cpp](https://github.com/ggml-org/llama.cpp) を通じてローカル GGUF モデルをサポートします。これらのモデルは手元のマシンで動き、LLM ピッカーで選んだときに必要に応じてダウンロードされます。
docs/ja-JP/explanation/technical-deep-dive.md CHANGED
@@ -4,19 +4,20 @@ title: 技術的な詳細解説
4
 
5
  # 技術的な詳細解説
6
 
7
- このページでは、Koharu の漫画翻訳パイプラインを技術面から説明します。各モデルが何をしているのか、各段階がどうつながるのか、そしてなぜレイアウト解析、segmentation mask、OCR、inpainting、翻訳を分けて扱うのかをまとめます。
8
 
9
  ## 実装ベースで見たページパイプライン
10
 
11
  ```mermaid
12
  flowchart TD
13
- A[Input page] --> B[PP-DocLayoutV3]
14
- A --> C[comic-text-detector]
15
- B --> D[Text blocks]
16
  C --> E[Segmentation mask]
17
  A --> F[YuzuMarker font detector]
 
18
  D --> G[PaddleOCR-VL crop OCR]
19
- E --> H[LaMa inpainting]
20
  G --> I[Local or remote LLM]
21
  F --> J[Renderer style hints]
22
  H --> K[Renderer]
@@ -27,7 +28,7 @@ flowchart TD
27
 
28
  コード上の公開パイプライン段階は `Detect -> OCR -> Inpaint -> LLM Generate -> Render` ですが、detect 段階の中で既に 3 つの別作業をしています。
29
 
30
- - ページのレイアウト解析
31
  - テキスト前景の segmentation
32
  - フォントと色の推定
33
 
@@ -37,22 +38,24 @@ flowchart TD
37
 
38
  | コンポーネント | 既定モデル | モデル種別 | Koharu での主な役割 |
39
  | --- | --- | --- | --- |
40
- | レイアウト解析 | [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors) | document layout detector | テキストらしい領域、ラベル、信頼度、読み順を見つける |
41
  | Segmentation | [comic-text-detector](https://github.com/dmMaze/comic-text-detector) | text segmentation network | クリーンアップ用の dense text mask を作る |
42
  | OCR | [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) | vision-language model | 切り出したテキスト領域を Unicode 文字列として読む |
43
- | Inpainting | [lama-manga](https://huggingface.co/mayocream/lama-manga) / [LaMa](https://github.com/advimman/lama) | image inpainting network | 文字除去後の masked 領域を埋める |
44
  | フォントヒント | [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection) | image classifier / regressor | フォント系統、色、縁取りヒントを推定する |
45
  | 翻訳 | [llama.cpp](https://github.com/ggml-org/llama.cpp) 経由のローカル GGUF モデル、またはリモート API | ローカルでは主に decoder-only LLM | OCR テキストを対象言語へ翻訳する |
46
 
47
- ## なぜ漫画ページでレイアウト解析が重要なのか
48
 
49
- レイアウト解析は、単に「テキストの周囲に box を置く」だけではありません。漫画ページでは、少なくとも次の構造的な問いに答える必要があります。
50
 
51
- - そもそもどの領域がテキストらしいか
52
- - おおよその読み順がどうなっているか
 
 
53
  - そのブロックが縦書きとして扱うべき縦長領域か
54
- - OCR 前にどの box を重複除去するべきか
55
- - その領域が caption、吹き出し本文、タイトル、その他レイアウト要素のどれに近いか
56
 
57
  漫画は視覚的に密度が高いので、ここが非常に重要です。
58
 
@@ -61,17 +64,16 @@ flowchart TD
61
  - ���書き日本語と横書きラテン文字が同じページに混在する
62
  - 読み取るべき領域の形と、消すべきピクセルの形が一致しないことがある
63
 
64
- Koharu はまずレイアウト出力から `TextBlock` を作り、それを OCR や後段のレンダリングの基盤にします。
65
 
66
- 現在の実装では、レイアウト段階は次のように動きます。
67
 
68
- - `PP-DocLayoutV3::inference_one_fast(...)` を実行する
69
- - テキストらしいラベルの領域を残す
70
- - それを `TextBlock` に変換する
71
- - 大きく重なった領域を重複除去する
72
- - 縦横比から縦書き / 横書き方向を推定する
73
 
74
- つまり、レイアウト解析はパイプライン全体の構造的な背骨です。
75
 
76
  ## segmentation mask とは何か
77
 
@@ -87,33 +89,31 @@ segmentation mask は、各ピクセルが対象クラスに属するかどう
87
 
88
  ```mermaid
89
  flowchart LR
90
- A[Speech bubble] --> B[Layout box]
91
  A --> C[Segmentation mask]
92
  B --> D[Crop for OCR]
93
  C --> E[Erase exact text pixels]
94
  ```
95
 
96
- Koharu では、segmentation 経路はレイアウトとは意図的に分離されています。
97
 
98
  - `comic-text-detector` がグレースケールの確率マップを出す
99
- - Koharu がそれを後処理で洗練する
100
- - 洗練後の結果が `doc.segment` になる
101
- - その後 LaMa が `doc.segment` を消去・補完用の mask として使う
102
 
103
- この洗練工程が重要なのは、生の segmentation 確率がたいていソフトでノイジーだからです。Koharu は予測を threshold し、text block を意識した refinement を試み、最終的な 2 値 mask を dilation して、文字の縁や輪郭が残って halo になるのを防ぎます。
104
 
105
  ## Vision モデルは理論上どう動くのか
106
 
107
- ### レイアウト解析: detector と読み順推定の組み合わせ
108
-
109
- [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3) は、傾きや湾曲など平面ではない歪みを含む文書解析向けのレイアウトモデルです。model card には、漫画ページでも重要な性質が 2 つあります。
110
 
111
- - 軸平行な 2 点 box だけでなく multi-point geometry を予測する
112
- - 同じ forward pass で論理的な読み順も予測する
113
 
114
- Koharu の Rust 実装もそれに沿っており、`pp_doclayout_v3` モジュールには `HGNetV2` バックボーンと attention ベースの encoder / decoder があり、推論結果として `label`、`score`、`bbox`、`polygon_points`、`order` が得られます。
 
115
 
116
- 概念的には、これは OCR そのものというより object detection と layout parsing に近い処理です。
117
 
118
  ### Segmentation: ピクセル密度の高いテキスト予測
119
 
@@ -123,10 +123,10 @@ Koharu の `comic-text-detector` 経路は segmentation-first な設計です。
123
  - mask 予測用の U-Net デコーダ
124
  - フル検出モード向けのオプション DBNet head
125
 
126
- 既定のページパイプラインでは segmentation-only 経路を使います。Koharu はすでに `PP-DocLayoutV3` からレイアウト box を得ているから��す。つまり Koharu は次の組み合わせを取っています。
127
 
128
- - ページ構造に強いモデル
129
- - ピクセル単位のテキスト前景抽出に強いモデル
130
 
131
  これは、box だけに頼るよりクリーンアップに向いた構成です。
132
 
@@ -150,36 +150,24 @@ Koharu の実装もかなりこの形に近いです。
150
  - `OCR:` をプロンプトに使う
151
  - 各 crop に対して greedily に文字列をデコードする
152
 
153
- つまり、Koharu の OCR は古典的な CTC 専用 recognizer ではなく、小型の document-oriented VLM を狭い OCR タスクに使っている形です。
154
-
155
- ### Inpainting: なぜ LaMa は Fourier convolution を使うのか
156
-
157
- [LaMa](https://github.com/advimman/lama) は、大きな mask 領域向けに設計された inpainting モデルです。論文タイトルでも、重要な発想は明示されています。*Resolution-robust Large Mask Inpainting with Fourier Convolutions* です。
158
-
159
- 直感的には、次の違いがあります。
160
-
161
- - 通常の convolution は局所的
162
- - テキスト除去では、吹き出しや背景の遠い文脈が必要になる
163
- - 周波数領域の演算は広域文脈を効率よく扱える
164
 
165
- ここで FFT が出てきます。
166
 
167
- #### ここでの FFT とは
168
 
169
- FFT は **Fast Fourier Transform** の略です。これは次の 2 つの表現の間を高速に行き来するアルゴリズムです。
 
 
170
 
171
- - 画素が存在する空間領域
172
- - 繰り返しパターンや大域構造を扱いやすい周波数領域
173
 
174
- Koharu の LaMa 実装では、`FourierUnit` がまさにこれを行います。
 
 
 
175
 
176
- 1. 特徴マップに `rfft2` を適用する
177
- 2. 実部と虚部チャネルに対して学習済み `1x1` convolution をかける
178
- 3. `irfft2` を適用して画像空間へ戻す
179
-
180
- Koharu は CPU / CUDA / Metal 向けに独自の `rfft2` と `irfft2` 演算も実装しているので、同じ spectral block を複数ハードウェアで走らせられます。
181
-
182
- 漫画のクリーンアップでは、欠損領域は小さな傷ではなく、グラデーションやスクリーントーン、線画端を含む吹き出し内部全体になることがあります。Fourier 系の大域混合は、穴を埋めながらより大きな構造を保つのに有利です。
183
 
184
  ## ローカル LLM とモデル種別
185
 
@@ -191,33 +179,32 @@ Koharu のローカル翻訳経路は、`llama.cpp` 経由で GGUF モデルを
191
  - 増えていく token 列に対して masked self-attention を実行する
192
  - 出力が終わるまで次 token を繰り返し予測する
193
 
194
- 実用上のトレードオフも一般的です。
195
-
196
- - 大きいモデルほど翻訳品質は高くなりやすい
197
- - 小さい量子化モデルほど VRAM と RAM を節約できる
198
- - リモートプロバイダは、ローカルのプライバシーと引き換えに大きなホスト型モデルを使いやすい
199
-
200
  リモートのテキスト生成プロバイダを使う場合でも、Koharu は画像理解段階をローカルで行います。リモート側が必要とするのは OCR テキストだけです。
201
 
202
  ## Koharu 固有の実装メモ
203
 
204
  高レベルの説明だけでは見落としやすい点を挙げると、次の通りです。
205
 
206
- - detect 段階では現在 `ComicTextDetector::load_segmentation_only(...)` を使っており、DBNet 付きフル検出モードではない
207
- - segmentation mask は inpainting 前に現在の text block に対して refinement される
 
208
  - OCR は元ページ全体ではなく、切り出した text block 画像に対して実行される
209
  - OCR ラッパーは multimodal llama.cpp 経路と `OCR:` プロンプトを使う
210
  - inpainting は `doc.segment` を消去 mask として使うので、mask が悪いとそのままクリーンアップ品質に出る
 
211
  - フォント予測結果はレンダリング前に正規化され、黒や白に近い色はよりきれいな値へ寄せられる
212
 
213
  ## 推奨読み物
214
 
215
  ### 公式モデル / プロジェクト資料
216
 
217
- - [PP-DocLayoutV3 model card](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3)
218
  - [PaddleOCR-VL-1.5 model card](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5)
219
  - [PaddleOCR-VL architecture docs in Hugging Face Transformers](https://huggingface.co/docs/transformers/en/model_doc/paddleocr_vl)
220
  - [comic-text-detector repository](https://github.com/dmMaze/comic-text-detector)
 
 
 
221
  - [LaMa repository](https://github.com/advimman/lama)
222
  - [llama.cpp](https://github.com/ggml-org/llama.cpp)
223
 
 
4
 
5
  # 技術的な詳細解説
6
 
7
+ このページでは、Koharu の漫画翻訳パイプラインを技術面から説明します。各モデルが何をしているのか、各段階がどうつながるのか、そしてなぜテキストと吹き出しの検出、segmentation mask、OCR、inpainting、翻訳を分けて扱うのかをまとめます。
8
 
9
  ## 実装ベースで見たページパイプライン
10
 
11
  ```mermaid
12
  flowchart TD
13
+ A[Input page] --> B[comic-text-bubble-detector]
14
+ A --> C[comic-text-detector-seg]
15
+ B --> D[Text blocks + bubbles]
16
  C --> E[Segmentation mask]
17
  A --> F[YuzuMarker font detector]
18
+ D --> C
19
  D --> G[PaddleOCR-VL crop OCR]
20
+ E --> H[AOT inpainting]
21
  G --> I[Local or remote LLM]
22
  F --> J[Renderer style hints]
23
  H --> K[Renderer]
 
28
 
29
  コード上の公開パイプライン段階は `Detect -> OCR -> Inpaint -> LLM Generate -> Render` ですが、detect 段階の中で既に 3 つの別作業をしています。
30
 
31
+ - テキストと吹き出しの検出
32
  - テキスト前景の segmentation
33
  - フォントと色の推定
34
 
 
38
 
39
  | コンポーネント | 既定モデル | モデル種別 | Koharu での主な役割 |
40
  | --- | --- | --- | --- |
41
+ | テキスト / 吹き出し検出 | [comic-text-bubble-detector](https://huggingface.co/ogkalu/comic-text-and-bubble-detector) | object detector | テキストブロックと吹き出し領域を見つける |
42
  | Segmentation | [comic-text-detector](https://github.com/dmMaze/comic-text-detector) | text segmentation network | クリーンアップ用の dense text mask を作る |
43
  | OCR | [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) | vision-language model | 切り出したテキスト領域を Unicode 文字列として読む |
44
+ | Inpainting | [aot-inpainting](https://huggingface.co/mayocream/aot-inpainting) / [manga-image-translator](https://github.com/zyddnys/manga-image-translator) | image inpainting network | 文字除去後の masked 領域を埋める |
45
  | フォントヒント | [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection) | image classifier / regressor | フォント系統、色、縁取りヒントを推定する |
46
  | 翻訳 | [llama.cpp](https://github.com/ggml-org/llama.cpp) 経由のローカル GGUF モデル、またはリモート API | ローカルでは主に decoder-only LLM | OCR テキストを対象言語へ翻訳する |
47
 
48
+ 組み込みの代替エンジンも残っています。主なものは、代替の検出 / レイアウト解析エンジンとしての [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors)、専用の吹き出し検出エンジンとしての [speech-bubble-segmentation](https://huggingface.co/mayocream/speech-bubble-segmentation)、代替 inpainter としての [lama-manga](https://huggingface.co/mayocream/lama-manga) です。
49
 
50
+ ## なぜテキストと吹き出しの検出が重要なのか
51
 
52
+ 検出は、単に「文字の周囲に box を置く」だけではありません。漫画ページでは少なくとも次の問いに答える必要があります。
53
+
54
+ - どの領域がテキストらしいか
55
+ - どこが吹き出しか
56
  - そのブロックが縦書きとして扱うべき縦長領域か
57
+ - OCR 前にどの box を重複除去すべきか
58
+ - どの領域を編集可能な `TextBlock` に変換すべきか
59
 
60
  漫画は視覚的に密度が高いので、ここが非常に重要です。
61
 
 
64
  - ���書き日本語と横書きラテン文字が同じページに混在する
65
  - 読み取るべき領域の形と、消すべきピクセルの形が一致しないことがある
66
 
67
+ Koharu は検出結果から `TextBlock` を作り、それを OCR や後段のレンダリングの基盤にします。吹き出し領域は別のジオメトリとして保持し、UI や後段処理で参照できるようにしています。
68
 
69
+ 現在の既定 detect 段階では、次のように動きます。
70
 
71
+ - Candle 版の `ogkalu/comic-text-and-bubble-detector` を実行する
72
+ - テキスト検出を `TextBlock` に変換する
73
+ - 吹き出し検出を `BubbleRegion` に変換する
74
+ - OCR 前に text block を漫画向けの読み順へ並べる
 
75
 
76
+ 文書レイアウト寄りの検出器を使いたい場合は、`PP-DocLayoutV3` も代替エンジンとして利用できます。ただし既定ではありません。
77
 
78
  ## segmentation mask とは何か
79
 
 
89
 
90
  ```mermaid
91
  flowchart LR
92
+ A[Speech bubble] --> B[Detected block]
93
  A --> C[Segmentation mask]
94
  B --> D[Crop for OCR]
95
  C --> E[Erase exact text pixels]
96
  ```
97
 
98
+ Koharu では、segmentation 経路は検出と意図的に分離されています。
99
 
100
  - `comic-text-detector` がグレースケールの確率マップを出す
101
+ - Koharu がそれを threshold と dilation で軽く後処理する
102
+ - 結果が `doc.segment` になる
103
+ - `aot-inpainting` が `doc.segment` を消去・補完用の mask として使う
104
 
105
+ この後処理が必要なのは、生の segmentation 確率がソフトでノイジーだからです。Koharu は予測を 2 値化し、最終 mask を dilation して、文字の縁や輪郭が残って halo になるのを減らします。
106
 
107
  ## Vision モデルは理論上どう動くのか
108
 
109
+ ### Joint detection: テキストブロックと吹き出しを 1 回で取る
 
 
110
 
111
+ [ogkalu/comic-text-and-bubble-detector](https://huggingface.co/ogkalu/comic-text-and-bubble-detector) を既定にしている理由は、後段が欲しい 2 種類の領域を直接返してくれるからです。
 
112
 
113
+ - `TextBlock` にしたいテキスト領域
114
+ - エディタや後段ツールで使いたい吹き出し領域
115
 
116
+ Koharu の Candle 版は、この検出結果をドキュメント構造へ変換し、OCR の前に text block を漫画向けの読み順へ並べます。概念的には OCR というよりページ object detection に近い処理です。
117
 
118
  ### Segmentation: ピクセル密度の高いテキスト予測
119
 
 
123
  - mask 予測用の U-Net デコーダ
124
  - フル検出モード向けのオプション DBNet head
125
 
126
+ 既定のページパイプラインでは segmentation-only 経路を使います。Koharu はすでに `comic-text-bubble-detector` から text block を得ているからです。つまり Koharu は次の組み合わせを取っています。
127
 
128
+ - ページ全体の領域検出が得意なモデル
129
+ - ピクセル単位のテキスト前景抽出が得意なモデル
130
 
131
  これは、box だけに頼るよりクリーンアップに向いた構成です。
132
 
 
150
  - `OCR:` をプロンプトに使う
151
  - 各 crop に対して greedily に文字列をデコードする
152
 
153
+ ### Inpainting: なぜ既定が AOT なのか
 
 
 
 
 
 
 
 
 
 
154
 
155
+ 既定の inpainter は [manga-image-translator](https://github.com/zyddnys/manga-image-translator) 由来の AOT モデルで、Koharu では `aot-inpainting` として公開しています。これは gated convolution と複数の dilation rate を持つ文脈混合ブロックを中心にした masked-image inpainting network です。
156
 
157
+ 直感的には、次のことが重要です。
158
 
159
+ - 文字除去は単純な矩形塗りつぶしでは足りない
160
+ - モデルには局所的なエッジ情報と、吹き出しや背景全体からの広めの文脈が必要
161
+ - 複数 dilation のブロックを繰り返すのは、その文脈を混ぜる実用的な方法
162
 
163
+ Koharu の Candle 版は upstream の推論形にかなり忠実です。
 
164
 
165
+ 1. 大きなページを設定された max side まで縮小する
166
+ 2. 作業画像を multiple-of-8 にそろえる
167
+ 3. masked RGB image と binary text mask をネットワークに入れる
168
+ 4. 予測したピクセルを元サイズの画像へ合成する
169
 
170
+ `lama-manga` も代替エンジンとして選べますが、既定ではありません。
 
 
 
 
 
 
171
 
172
  ## ローカル LLM とモデル種別
173
 
 
179
  - 増えていく token 列に対して masked self-attention を実行する
180
  - 出力が終わるまで次 token を繰り返し予測する
181
 
 
 
 
 
 
 
182
  リモートのテキスト生成プロバイダを使う場合でも、Koharu は画像理解段階をローカルで行います。リモート側が必要とするのは OCR テキストだけです。
183
 
184
  ## Koharu 固有の実装メモ
185
 
186
  高レベルの説明だけでは見落としやすい点を挙げると、次の通りです。
187
 
188
+ - 既定の detect 段階は `PP-DocLayoutV3` ではなく `comic-text-bubble-detector`
189
+ - `comic-text-detector-seg` は `doc.segment` 用に segmentation-only の `comic-text-detector` 経路を使う
190
+ - segmentation mask は現在、古い block-aware refinement ではなく threshold と dilation で作る
191
  - OCR は元ページ全体ではなく、切り出した text block 画像に対して実行される
192
  - OCR ラッパーは multimodal llama.cpp 経路と `OCR:` プロンプトを使う
193
  - inpainting は `doc.segment` を消去 mask として使うので、mask が悪いとそのままクリーンアップ品質に出る
194
+ - 既定の inpainter は `aot-inpainting` で、`lama-manga` は代替として選択可能
195
  - フォント予測結果はレンダリング前に正規化され、黒や白に近い色はよりきれいな値へ寄せられる
196
 
197
  ## 推奨読み物
198
 
199
  ### 公式モデル / プロジェクト資料
200
 
201
+ - [comic-text-and-bubble-detector model card](https://huggingface.co/ogkalu/comic-text-and-bubble-detector)
202
  - [PaddleOCR-VL-1.5 model card](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5)
203
  - [PaddleOCR-VL architecture docs in Hugging Face Transformers](https://huggingface.co/docs/transformers/en/model_doc/paddleocr_vl)
204
  - [comic-text-detector repository](https://github.com/dmMaze/comic-text-detector)
205
+ - [manga-image-translator repository](https://github.com/zyddnys/manga-image-translator)
206
+ - [YuzuMarker.FontDetection model card](https://huggingface.co/fffonion/yuzumarker-font-detection)
207
+ - [PP-DocLayoutV3 model card](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3)
208
  - [LaMa repository](https://github.com/advimman/lama)
209
  - [llama.cpp](https://github.com/ggml-org/llama.cpp)
210
 
docs/ja-JP/index.md CHANGED
@@ -494,7 +494,7 @@ hide:
494
  </div>
495
  <div class="kh-download-hero">
496
  <a class="kh-download-button" href="https://github.com/mayocream/koharu/releases/latest">
497
- Windows 版をダウンロード&nbsp;&nbsp;<span class="kh-download-button__version">0.40.1</span>
498
  </a>
499
  <div class="kh-download-hero__subtext">
500
  Koharu は無料のオープンソースソフトウェアです。
 
494
  </div>
495
  <div class="kh-download-hero">
496
  <a class="kh-download-button" href="https://github.com/mayocream/koharu/releases/latest">
497
+ Windows 版をダウンロード&nbsp;&nbsp;<span class="kh-download-button__version">0.42.1</span>
498
  </a>
499
  <div class="kh-download-hero__subtext">
500
  Koharu は無料のオープンソースソフトウェアです。
docs/zh-CN/explanation/how-koharu-works.md CHANGED
@@ -4,19 +4,20 @@ title: Koharu 的工作方式
4
 
5
  # Koharu 的工作方式
6
 
7
- Koharu 围绕一条漫画翻译页面管线构建。用户看到的流程很简单,但实现上会刻意把版面分析、分割、OCR、修复、翻译和渲染拆成独立阶段。
8
 
9
  ## 管线总览
10
 
11
  ```mermaid
12
  flowchart LR
13
  A[输入漫画页面] --> B[Detect 阶段]
14
- B --> B1[版面分析]
15
  B --> B2[分割掩码]
16
  B --> B3[字体提示]
17
  B1 --> C[OCR 阶段]
18
  B2 --> D[修复阶段]
19
  C --> E[LLM 翻译阶段]
 
20
  D --> F[渲染阶段]
21
  E --> F
22
  F --> G[本地化页面或 PSD 导出]
@@ -32,19 +33,19 @@ flowchart LR
32
 
33
  关键实现细节在于,`Detect` 本身已经是一个多模型阶段:
34
 
35
- - `PP-DocLayoutV3` 负责找出类似文本的版面区域和阅读顺序
36
- - `comic-text-detector` 生成逐像素的文本概率图
37
  - `YuzuMarker.FontDetection` 估计后续渲染要用到的字体与颜色提示
38
 
39
- 正因为如此,Koharu 才能让一个模型负责“文字应该属于页面哪里”,另一个模型负责“究竟哪些像素应该被擦掉”。
40
 
41
  ## 每个阶段产出什么
42
 
43
  | 阶段 | 主要模型 | 主要输出 |
44
  | --- | --- | --- |
45
- | Detect | `PP-DocLayoutV3`, `comic-text-detector`, `YuzuMarker.FontDetection` | 文本块、分割掩码、字体提示 |
46
  | OCR | `PaddleOCR-VL-1.5` | 每个文本块识别出的原文 |
47
- | Inpaint | `lama-manga` | 去除原文后的页面 |
48
  | LLM Generate | 本地 GGUF LLM 或远程提供商 | 译文 |
49
  | Render | Koharu renderer | 最终本地化页面或导出内容 |
50
 
@@ -53,24 +54,24 @@ flowchart LR
53
  漫画页面比普通文档 OCR 更难:
54
 
55
  - 气泡形状不规则,经常弯曲
56
- - 日文可能是纵排,旁边的注释或 SFX 又可能是横排
57
  - 文本会压在背景、网点、速度线和分镜边框之上
58
  - 阅读顺序本身就是页面结构的一部分,不只是像素问题
59
 
60
- 因此通常不能指望一个模型把所有事情都做好。Koharu 会先估计版面,再对裁剪出的区域做 OCR,再用分割掩码做清理,最后才把文本交给 LLM 翻译。
61
 
62
  ## 实现结构
63
 
64
- 从源码结构看,管线入口在 `koharu-app/src/pipeline.rs`,视觉栈的协调逻辑主要在 `koharu-app/src/ml.rs`。
65
 
66
  一些重要的实现细节:
67
 
68
- - detect 阶段先跑 `PP-DocLayoutV3`,再把文本类标签转换成 `TextBlock`
69
- - OCR 之前会先去重高度重叠的框
70
- - 文本方向会基于区域长宽比推断,这样纵排漫画文本能更早进入正确路径
71
  - OCR 运行在裁剪后的文本区域上,而不是整页图像
72
  - 修复阶段使用的是当前分割掩码,而不是简单矩形框
73
- - 当你选择远程 LLM 时,Koharu 发送出去的是 OCR 文本,而不是整页图像
 
74
 
75
  ## 为什么这套技术栈很重要
76
 
@@ -92,6 +93,4 @@ Koharu 使用:
92
 
93
  ## 想看更深的技术版本?
94
 
95
- 请参见 [技术深潜](technical-deep-dive.md),了解模型类型、分割掩码理论、基于 FFT 的修复,以及维基百科图示和官方模型卡的背景说明。关于渲染器、纵排写字模式和当前版面限制,请参见 [文本渲染与纵排 CJK 布局](text-rendering-and-vertical-cjk-layout.md)。
96
-
97
-
 
4
 
5
  # Koharu 的工作方式
6
 
7
+ Koharu 围绕一条漫画翻译页面管线构建。用户看到的流程很简单,但实现上会刻意把联合检测、分割、OCR、修复、翻译和渲染拆成独立阶段。
8
 
9
  ## 管线总览
10
 
11
  ```mermaid
12
  flowchart LR
13
  A[输入漫画页面] --> B[Detect 阶段]
14
+ B --> B1[文本块和气泡区域]
15
  B --> B2[分割掩码]
16
  B --> B3[字体提示]
17
  B1 --> C[OCR 阶段]
18
  B2 --> D[修复阶段]
19
  C --> E[LLM 翻译阶段]
20
+ B3 --> F
21
  D --> F[渲染阶段]
22
  E --> F
23
  F --> G[本地化页面或 PSD 导出]
 
33
 
34
  关键实现细节在于,`Detect` 本身已经是一个多模型阶段:
35
 
36
+ - `comic-text-bubble-detector` 负责找出文本块和气泡区域
37
+ - `comic-text-detector-seg` 生成逐像素文本概率图,并将其变成清理掩码
38
  - `YuzuMarker.FontDetection` 估计后续渲染要用到的字体与颜色提示
39
 
40
+ 正因为如此,Koharu 才能让一个模型负责“文字在哪里”,另一个模型负责“哪些像素应该被擦掉”。
41
 
42
  ## 每个阶段产出什么
43
 
44
  | 阶段 | 主要模型 | 主要输出 |
45
  | --- | --- | --- |
46
+ | Detect | `comic-text-bubble-detector`, `comic-text-detector-seg`, `YuzuMarker.FontDetection` | 文本块、气泡区域、分割掩码、字体提示 |
47
  | OCR | `PaddleOCR-VL-1.5` | 每个文本块识别出的原文 |
48
+ | Inpaint | `aot-inpainting` | 去除原文后的页面 |
49
  | LLM Generate | 本地 GGUF LLM 或远程提供商 | 译文 |
50
  | Render | Koharu renderer | 最终本地化页面或导出内容 |
51
 
 
54
  漫画页面比普通文档 OCR 更难:
55
 
56
  - 气泡形状不规则,经常弯曲
57
+ - 日文可能是竖排,旁边的注释或 SFX 又可能是横排
58
  - 文本会压在背景、网点、速度线和分镜边框之上
59
  - 阅读顺序本身就是页面结构的一部分,不只是像素问题
60
 
61
+ 因此通常不能指望一个模型把所有事情都做好。Koharu 会先找出文本块和气泡区域,再对裁剪区域做 OCR,再用分割掩码做清理,最后才把文本交给 LLM 翻译。
62
 
63
  ## 实现结构
64
 
65
+ 从源码结构看,引擎注册和管线执行在 `koharu-app/src/engine.rs`,默认引擎选择在 `koharu-app/src/config.rs`。
66
 
67
  一些重要的实现细节:
68
 
69
+ - 默认 detect 引擎是 `comic-text-bubble-detector`,会在一次推理里写入 `TextBlock` 和气泡区域
70
+ - `comic-text-detector-seg` 会在已有 text block 后运行,并把最终掩码保存为 `doc.segment`
 
71
  - OCR 运行在裁剪后的文本区域上,而不是整页图像
72
  - 修复阶段使用的是当前分割掩码,而不是简单矩形框
73
+ - 当你选择远程 LLM 时,Koharu 发出去的是 OCR 文本,而不是整页图像
74
+ - 你可以在 **Settings > Engines** 中替换单个阶段,而无需改动整条管线
75
 
76
  ## 为什么这套技术栈很重要
77
 
 
93
 
94
  ## 想看更深的技术版本?
95
 
96
+ 请参见 [技术深潜](technical-deep-dive.md),了解模型类型、分割掩码理论、AOT 修复,以及官方模型卡的背景说明。关于渲染器、竖排写字模式和当前版面限制,请参见 [文本渲染与竖排 CJK 布局](text-rendering-and-vertical-cjk-layout.md)。
 
 
docs/zh-CN/explanation/models-and-providers.md CHANGED
@@ -12,32 +12,41 @@ Koharu 同时使用视觉模型和语言模型。视觉栈负责准备页面,
12
 
13
  Koharu 会在首次使用时自动下载所需的视觉模型。
14
 
15
- 默认栈包括:
16
 
17
- - [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors):文本检测与版面分析
18
- - [comic-text-detector](https://huggingface.co/mayocream/comic-text-detector):文本分割
19
- - [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5):OCR 文本识别
20
- - [lama-manga](https://huggingface.co/mayocream/lama-manga):图像修复
21
- - [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection):字体与颜色检测
22
 
23
- 为兼容 Rust 运行时并获得更好的性能,转换后的模型权重以 safetensors 格式托管在 [Hugging Face](https://huggingface.co/mayocream) 上。
24
 
25
  ### 每个视觉模型是什么
26
 
27
  | 模型 | 模型类型 | Koharu 使用它的原因 |
28
  | --- | --- | --- |
29
- | `PP-DocLayoutV3` | 版面检测器 | 找出文本类区域与阅读顺序 |
30
  | `comic-text-detector` | 分割网络 | 生成清理用的文本掩码 |
31
  | `PaddleOCR-VL-1.5` | 视觉语言模型 | 把裁剪图像读成文本 token |
32
- | `lama-manga` | 修复网络 | 在去字后重建底图 |
33
  | `YuzuMarker.FontDetection` | 分类 / 回归模型 | 为渲染估计字体与风格提示 |
34
 
35
- 最重要的设计点是:Koharu 不会用一个模型硬扛所有页面任务。版面、分割、OCR 和修复需要完全不同的输出形式:
36
 
37
- - 版面要区域与顺序
38
- - 分割要逐像素掩码
39
- - OCR 要文本
40
- - 修复要恢复后的像素
 
 
 
 
 
 
 
 
 
41
 
42
  ## 本地 LLM
43
 
 
12
 
13
  Koharu 会在首次使用时自动下载所需的视觉模型。
14
 
15
+ 当前默认栈包括:
16
 
17
+ - 用于同时检测文本块和气泡的 [comic-text-bubble-detector](https://huggingface.co/ogkalu/comic-text-and-bubble-detector)
18
+ - 用于生成文本分割掩码的 [comic-text-detector](https://huggingface.co/mayocream/comic-text-detector)
19
+ - 用于 OCR 文本识别的 [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5)
20
+ - 作为默认修复器的 [aot-inpainting](https://huggingface.co/mayocream/aot-inpainting)
21
+ - 用于字体与颜色检测的 [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection)
22
 
23
+ 有些模型直接使用上游 Hugging Face 仓库,另一些则因为 Koharu 需要 Rust 友好的 safetensors 版本,而由 [Hugging Face](https://huggingface.co/mayocream) 托管转换后的权重。
24
 
25
  ### 每个视觉模型是什么
26
 
27
  | 模型 | 模型类型 | Koharu 使用它的原因 |
28
  | --- | --- | --- |
29
+ | `comic-text-bubble-detector` | object detector | 一次推理同时找出文本块和气泡区域 |
30
  | `comic-text-detector` | 分割网络 | 生成清理用的文本掩码 |
31
  | `PaddleOCR-VL-1.5` | 视觉语言模型 | 把裁剪图像读成文本 token |
32
+ | `aot-inpainting` | 修复网络 | 在去字后补全被掩码覆盖的区域 |
33
  | `YuzuMarker.FontDetection` | 分类 / 回归模型 | 为渲染估计字体与风格提示 |
34
 
35
+ 最重要的设计点是:Koharu 不会用一个模型硬扛所有页面任务。检测、分割、OCR 和修复需要完全不同的输出形式:
36
 
37
+ - 联合检测需要文本块和气泡区域
38
+ - 分割需要逐像素掩码
39
+ - OCR 需要文本
40
+ - 修复需要恢复后的像素
41
+
42
+ ### 内置可选替代引擎
43
+
44
+ 你可以在 **Settings > Engines** 中按阶段替换模型。内置替代项包括:
45
+
46
+ - 作为替代检测 / 版面分析引擎的 [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors)
47
+ - 作为专用气泡检测器的 [speech-bubble-segmentation](https://huggingface.co/mayocream/speech-bubble-segmentation)
48
+ - 作为替代 OCR 的 [Manga OCR](https://huggingface.co/mayocream/manga-ocr) 和 [MIT 48px OCR](https://huggingface.co/mayocream/mit48px-ocr)
49
+ - 作为替代修复器的 [lama-manga](https://huggingface.co/mayocream/lama-manga)
50
 
51
  ## 本地 LLM
52
 
docs/zh-CN/explanation/technical-deep-dive.md CHANGED
@@ -4,19 +4,20 @@ title: 技术深潜
4
 
5
  # 技术深潜
6
 
7
- 本页解释 Koharu 漫画处理管线的技术侧面:每个模型做什么、各阶段如何拼在一起,以及为什么漫画翻译必须把版面分析、分割掩码、OCR、修复和翻译拆开处理。
8
 
9
  ## 从实现角度看页面管线
10
 
11
  ```mermaid
12
  flowchart TD
13
- A[输入页面] --> B[PP-DocLayoutV3]
14
- A --> C[comic-text-detector]
15
- B --> D[文本块]
16
  C --> E[分割掩码]
17
  A --> F[YuzuMarker font detector]
 
18
  D --> G[PaddleOCR-VL 裁剪 OCR]
19
- E --> H[LaMa 修复]
20
  G --> I[本地或远程 LLM]
21
  F --> J[渲染样式提示]
22
  H --> K[Renderer]
@@ -27,7 +28,7 @@ flowchart TD
27
 
28
  从公开 API 看,Koharu 的主要流程是 `Detect -> OCR -> Inpaint -> LLM Generate -> Render`,但 detect 阶段本身已经同时做了三类工作:
29
 
30
- - 页面版面分析
31
  - 文本前景分割
32
  - 字体与颜色估计
33
 
@@ -37,41 +38,42 @@ flowchart TD
37
 
38
  | 组件 | 默认模型 | 模型类型 | 在 Koharu 中的主要任务 |
39
  | --- | --- | --- | --- |
40
- | 版面分析 | [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors) | 文档版面检测器 | 找出文本类区域、标签、置信度与阅读顺序 |
41
  | 分割 | [comic-text-detector](https://github.com/dmMaze/comic-text-detector) | 文本分割网络 | 生成用于清理的高密度文本掩码 |
42
  | OCR | [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) | 视觉语言模型 | 将裁剪文本区域识别为 Unicode 文本 |
43
- | 修复 | [lama-manga](https://huggingface.co/mayocream/lama-manga) / [LaMa](https://github.com/advimman/lama) | 图像修复网络 | 在去字后填补遮挡区域 |
44
  | 字体提示 | [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection) | 图像分类 / 回归模型 | 估计字体、颜色与描边提示 |
45
  | 翻译 | 通过 [llama.cpp](https://github.com/ggml-org/llama.cpp) 运行的本地 GGUF 模型,或远程 API | 大多数本地场景下是 decoder-only LLM | 将 OCR 文本翻译到目标语言 |
46
 
47
- ## 为什么漫画页面特别需要版面分析
48
 
49
- 版面分析不只是“给文本画框”。在漫画页里,它还要回答:
50
 
51
- - 哪些区域根本像文本
52
- - 大致的阅读顺序是什么
53
- - 某个文本块是否高到足以被当成纵排
 
 
54
  - 哪些框应该在 OCR 前先去重
55
- - 哪些区域是气泡、旁白、标题或其他版面类别
56
 
57
  这是因为漫画页面本来就结构复杂:
58
 
59
  - 气泡常常弯曲或倾斜
60
  - 文本可能压在网点、速度线和复杂背景上
61
- - 纵排日文和横排拉丁文本会同时存在
62
  - 应该“读”的区域,与应该“擦掉”的像素,形状往往并不一样
63
 
64
- Koharu 先根据布局输出创建 `TextBlock`,再用这些块驱动 OCR 和后续渲染。
65
 
66
- 在当前实现里,布局阶段会:
67
 
68
- - 运行 `PP-DocLayoutV3::inference_one_fast(...)`
69
- - 保留看起来像文本的标签区域
70
- - 将它们转换成 `TextBlock`
71
- - 去除高度重叠的候选框
72
- - 根据长宽比推断横排还是纵排
73
 
74
- 因此,版面分析是整条漫画处理管线的结构骨架。
75
 
76
  ## 什么是分割掩码
77
 
@@ -87,33 +89,31 @@ Koharu 先根据布局输出创建 `TextBlock`,再用这些块驱动 OCR 和
87
 
88
  ```mermaid
89
  flowchart LR
90
- A[气泡区域] --> B[布局框]
91
  A --> C[分割掩码]
92
  B --> D[OCR 裁剪]
93
  C --> E[擦除精确文本像素]
94
  ```
95
 
96
- 在 Koharu 中,分割路径有意和布局路径分开:
97
 
98
  - `comic-text-detector` 生成灰度概率图
99
- - Koharu 对概率图做后处理和细化
100
- - 细化结果存入 `doc.segment`
101
- - LaMa 再用 `doc.segment` 作为擦除与填补掩码
102
 
103
- 这个细化步骤很重要,因为原始分割概率通常是软的、带噪声的。Koharu 会对其阈值化、结合文本块做细化,并对最终二值掩码做膨胀,尽量覆盖文字边缘和描边,减少残影。
104
 
105
  ## 这些视觉模型在理论上如何工作
106
 
107
- ### 版面分析:检测器加阅读顺序推断
108
-
109
- [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3) 是一个面向文档解析的布局模型,擅长处理倾斜、形变和非平面失真。它的模型卡中有两个对漫画页尤其重要的点:
110
 
111
- - 它预测的是多点几何,而不只是轴对齐矩形框
112
- - 它会在同一次前向中同时预测逻辑阅读顺序
113
 
114
- Koharu 的 Rust 端口保留了这种结构:`pp_doclayout_v3` 模块包含 `HGNetV2` 骨干以及注意力式编码器 / 解码器块,推理结果会暴露 `label`、`score`、`bbox`、`polygon_points` 和 `order`。
 
115
 
116
- 从概念上说,这更接近“目标检测 + 版面解析”,而不是单纯 OCR。
117
 
118
  ### 分割:密集逐像素文本预测
119
 
@@ -123,10 +123,10 @@ Koharu 的 `comic-text-detector` 路径本质上是以分割为核心的设计
123
  - 用于掩码预测的 U-Net 解码器
124
  - 可选的 DBNet 检测头
125
 
126
- 默认页面管线使用“仅分割”路径,因为 Koharu 已经从 `PP-DocLayoutV3` 获得了布局框。也就是说,Koharu 组合了:
127
 
128
- - 一个擅长页面结构的模型
129
- - 一个擅长像素级文本前景的模型
130
 
131
  对于图像清理来说,这比只靠边界框更合适。
132
 
@@ -150,36 +150,24 @@ Koharu 的实现非常接近这种模式:
150
  - 使用 `OCR:` 作为提示
151
  - 对每个裁剪块贪心解码文本
152
 
153
- 因此,Koharu 里的 OCR 并不是传统的纯 CTC 识别器,而是一个被限定在 OCR 任务上的小型文档 VLM。
154
-
155
- ### 修复:为什么 LaMa 使用傅里叶卷积
156
-
157
- [LaMa](https://github.com/advimman/lama) 是一个面向大面积遮挡区域的图像修复模型。它论文标题就点明了核心思路:*Resolution-robust Large Mask Inpainting with Fourier Convolutions*。
158
-
159
- 直觉上:
160
-
161
- - 普通卷积擅长局部信息
162
- - 去字修复往往需要从更大范围背景中借上下文
163
- - 频域操作可以更高效地建模大尺度结构
164
 
165
- 这里就会用到 FFT。
166
 
167
- #### 这里的 FFT 是什么意思
168
 
169
- FFT 是 **Fast Fourier Transform(快速傅里叶变换)**,它是一种在以下两个空间之间快速切换的算法:
 
 
170
 
171
- - 像素所在的空间域
172
- - 更容易表达重复模式和大尺度结构的频域
173
 
174
- 在 Koharu 的 LaMa 端口里,`FourierUnit` 会:
 
 
 
175
 
176
- 1. 对特征图做 `rfft2`
177
- 2. 对实部与虚部通道应用学习得到的 `1x1` 卷积
178
- 3. 再用 `irfft2` 回到图像空间
179
-
180
- Koharu 甚至为 CPU、CUDA 和 Metal 实现了自定义 `rfft2` / `irfft2` 操作,因此同一套频域块可以跨硬件运行。
181
-
182
- 对于漫画清理来说,这很关键,因为缺失区域往往不是一个小洞,而可能是整个气泡内侧,里面还带着渐变、网点和边缘线稿。频域的全局混合能力更有利于保留大结构。
183
 
184
  ## 本地 LLM 与模型类型
185
 
@@ -191,33 +179,32 @@ Koharu 的本地翻译路径通过 `llama.cpp` 使用 GGUF 模型。实际中,
191
  - 在不断增长的 token 序列上执行 masked self-attention
192
  - 反复预测下一个 token,直到完成输出
193
 
194
- 实际取舍也很标准:
195
-
196
- - 模型越大,通常翻译越好
197
- - 更小的量化模型占用更少的 VRAM 和 RAM
198
- - 远程提供商可以提供更大模型,但会带来隐私与依赖外部服务的权衡
199
-
200
  即使你使用远程文本生成提供商,Koharu 也会把图像理解步骤留在本地。远端拿到的只是 OCR 文本。
201
 
202
  ## Koharu 实现中特别值得注意的点
203
 
204
  如果你只看高层文档,下面这些实现细节很容易被忽略:
205
 
206
- - detect 阶段当前加载的是 `ComicTextDetector::load_segmentation_only(...)`,而不是启用 DBNet 的完整检测模式
207
- - 分割掩码会结合当前检测出的文本块做精细化,再进入修复阶段
 
208
  - OCR 运行在裁剪后的文本块图像上,而不是整页原图
209
  - OCR 封装使用的是 `llama.cpp` 的多模态路径,并采用 `OCR:` 提示
210
  - 修复阶段直接消费 `doc.segment`,所以糟糕的掩码会直接导致糟糕的清理结果
 
211
  - 渲染前会对字体预测做归一化,让接近纯黑或纯白的颜色更稳定
212
 
213
  ## 推荐阅读
214
 
215
  ### 官方模型与项目参考
216
 
217
- - [PP-DocLayoutV3 model card](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3)
218
  - [PaddleOCR-VL-1.5 model card](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5)
219
  - [Hugging Face Transformers 中的 PaddleOCR-VL 架构文档](https://huggingface.co/docs/transformers/en/model_doc/paddleocr_vl)
220
  - [comic-text-detector 仓库](https://github.com/dmMaze/comic-text-detector)
 
 
 
221
  - [LaMa 仓库](https://github.com/advimman/lama)
222
  - [llama.cpp](https://github.com/ggml-org/llama.cpp)
223
 
 
4
 
5
  # 技术深潜
6
 
7
+ 本页解释 Koharu 漫画处理管线的技术侧面:每个模型做什么、各阶段如何拼在一起,以及为什么漫画翻译必须把文本与气泡检测、分割掩码、OCR、修复和翻译拆开处理。
8
 
9
  ## 从实现角度看页面管线
10
 
11
  ```mermaid
12
  flowchart TD
13
+ A[输入页面] --> B[comic-text-bubble-detector]
14
+ A --> C[comic-text-detector-seg]
15
+ B --> D[文本块 + 气泡]
16
  C --> E[分割掩码]
17
  A --> F[YuzuMarker font detector]
18
+ D --> C
19
  D --> G[PaddleOCR-VL 裁剪 OCR]
20
+ E --> H[AOT 修复]
21
  G --> I[本地或远程 LLM]
22
  F --> J[渲染样式提示]
23
  H --> K[Renderer]
 
28
 
29
  从公开 API 看,Koharu 的主要流程是 `Detect -> OCR -> Inpaint -> LLM Generate -> Render`,但 detect 阶段本身已经同时做了三类工作:
30
 
31
+ - 文本和气泡检测
32
  - 文本前景分割
33
  - 字体与颜色估计
34
 
 
38
 
39
  | 组件 | 默认模型 | 模型类型 | 在 Koharu 中的主要任务 |
40
  | --- | --- | --- | --- |
41
+ | 文本 / 气泡检测 | [comic-text-bubble-detector](https://huggingface.co/ogkalu/comic-text-and-bubble-detector) | object detector | 找出文本块和气泡区域 |
42
  | 分割 | [comic-text-detector](https://github.com/dmMaze/comic-text-detector) | 文本分割网络 | 生成用于清理的高密度文本掩码 |
43
  | OCR | [PaddleOCR-VL-1.5](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5) | 视觉语言模型 | 将裁剪文本区域识别为 Unicode 文本 |
44
+ | 修复 | [aot-inpainting](https://huggingface.co/mayocream/aot-inpainting) / [manga-image-translator](https://github.com/zyddnys/manga-image-translator) | 图像修复网络 | 在去字后填补遮挡区域 |
45
  | 字体提示 | [YuzuMarker.FontDetection](https://huggingface.co/fffonion/yuzumarker-font-detection) | 图像分类 / 回归模型 | 估计字体、颜色与描边提示 |
46
  | 翻译 | 通过 [llama.cpp](https://github.com/ggml-org/llama.cpp) 运行的本地 GGUF 模型,或远程 API | 大多数本地场景下是 decoder-only LLM | 将 OCR 文本翻译到目标语言 |
47
 
48
+ 内置替代引擎仍然可用。主要包括:作为替代检测 / 版面分析引擎的 [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3_safetensors)、作为专用气泡检测器的 [speech-bubble-segmentation](https://huggingface.co/mayocream/speech-bubble-segmentation),以及作为替代修复器的 [lama-manga](https://huggingface.co/mayocream/lama-manga)。
49
 
50
+ ## 为什么文本和气泡检测在漫画页上很重要
51
 
52
+ 检测不只是“给文字画框”。在漫画页里,它还要回答:
53
+
54
+ - 哪些区域看起来像文本
55
+ - 哪些区域是气泡
56
+ - 某个文本块是否高到足以被当成竖排
57
  - 哪些框应该在 OCR 前先去重
58
+ - 哪些区域应该被转换成可编辑的 `TextBlock`
59
 
60
  这是因为漫画页面本来就结构复杂:
61
 
62
  - 气泡常常弯曲或倾斜
63
  - 文本可能压在网点、速度线和复杂背景上
64
+ - 竖排日文和横排拉丁文本会同时存在
65
  - 应该“读”的区域,与应该“擦掉”的像素,形状往往并不一样
66
 
67
+ Koharu 先根据检测结果创建 `TextBlock`,再用这些块驱动 OCR 和后续渲染。气泡区域会单独保留下来,供 UI 和后续工具继续使用。
68
 
69
+ 在当前默认实现里,detect 阶段会:
70
 
71
+ - 运行 Candle 版 `ogkalu/comic-text-and-bubble-detector`
72
+ - 把文本检测结果转换成 `TextBlock`
73
+ - 把气泡检测结果转换成 `BubbleRegion`
74
+ - 在 OCR 前按漫画阅读顺序整理 text block
 
75
 
76
+ 如果你更想用偏文档版面的检测器,`PP-DocLayoutV3` 仍然可以作为替代引擎使用,只是不再是默认选择。
77
 
78
  ## 什么是分割掩码
79
 
 
89
 
90
  ```mermaid
91
  flowchart LR
92
+ A[气泡区域] --> B[检测框]
93
  A --> C[分割掩码]
94
  B --> D[OCR 裁剪]
95
  C --> E[擦除精确文本像素]
96
  ```
97
 
98
+ 在 Koharu 中,分割路径有意和检测路径分开:
99
 
100
  - `comic-text-detector` 生成灰度概率图
101
+ - Koharu 对它做阈值化和膨胀等轻量后处理
102
+ - 结果保存到 `doc.segment`
103
+ - `aot-inpainting` 再把 `doc.segment` 作为擦除与填补掩码
104
 
105
+ 这个后处理步骤仍然重要,因为原始分割概率通常是软的、带噪声的。Koharu 会先二值化,再对最终掩码做膨胀,尽量覆盖文字边缘和描边,减少残影。
106
 
107
  ## 这些视觉模型在理论上如何工作
108
 
109
+ ### 联合检测:一次得到文本块和气泡区域
 
 
110
 
111
+ [ogkalu/comic-text-and-bubble-detector](https://huggingface.co/ogkalu/comic-text-and-bubble-detector) 成为默认检测器,是因为它直接预测了后续最关心的两类区域:
 
112
 
113
+ - 应该转换成 `TextBlock` 的文本区域
114
+ - 应该继续保留给编辑器和后续工具使用的气泡区域
115
 
116
+ Koharu 的 Candle 端口会把这些检测结果映射到文档结构里,并在 OCR 前按漫画阅读顺序排序文本块。从概念上说,这更接近页面目标检测,而不是 OCR 本身。
117
 
118
  ### 分割:密集逐像素文本预测
119
 
 
123
  - 用于掩码预测的 U-Net 解码器
124
  - 可选的 DBNet 检测头
125
 
126
+ 默认页面管线使用“仅分割”路径,因为 Koharu 已经从 `comic-text-bubble-detector` 获得了 text block。也就是说,Koharu 组合了:
127
 
128
+ - 一个擅长页面级区域检测的模型
129
+ - 一个擅长像素级文本前景抽取的模型
130
 
131
  对于图像清理来说,这比只靠边界框更合适。
132
 
 
150
  - 使用 `OCR:` 作为提示
151
  - 对每个裁剪块贪心解码文本
152
 
153
+ ### 修复:为什么默认改成了 AOT
 
 
 
 
 
 
 
 
 
 
154
 
155
+ 默认修复器是来自 [manga-image-translator](https://github.com/zyddnys/manga-image-translator) 的 AOT 模型,在 Koharu 中叫 `aot-inpainting`。它是一种 masked-image inpainting network,核心是 gated convolution 和带有多个 dilation rate 的上下文混合块。
156
 
157
+ 直觉上,关键点在于:
158
 
159
+ - 去字修复不是简单的矩形填充
160
+ - 模型既要看到局部边缘细节,也要借用更大范围的气泡或背景上下文
161
+ - 多膨胀率上下文块是一种务实的上下文混合方式
162
 
163
+ Koharu 的 Candle 端口基本遵循上游推理流程:
 
164
 
165
+ 1. 把过大的页面缩到设定的 max side
166
+ 2. 把工作图像补齐到 multiple-of-8
167
+ 3. 将 masked RGB 图像和二值文本掩码送入网络
168
+ 4. 再把预测像素合成回原尺寸图像
169
 
170
+ `lama-manga` 仍然可以作为替代引擎选择,但已经不是默认项。
 
 
 
 
 
 
171
 
172
  ## 本地 LLM 与模型类型
173
 
 
179
  - 在不断增长的 token 序列上执行 masked self-attention
180
  - 反复预测下一个 token,直到完成输出
181
 
 
 
 
 
 
 
182
  即使你使用远程文本生成提供商,Koharu 也会把图像理解步骤留在本地。远端拿到的只是 OCR 文本。
183
 
184
  ## Koharu 实现中特别值得注意的点
185
 
186
  如果你只看高层文档,下面这些实现细节很容易被忽略:
187
 
188
+ - 默认 detect 阶段是 `comic-text-bubble-detector`,而不是 `PP-DocLayoutV3`
189
+ - `comic-text-detector-seg` 仍然走 segmentation-only 的 `comic-text-detector` 路径来生成 `doc.segment`
190
+ - 分割掩码现在是通过阈值化加膨胀构建的,不再走旧的 block-aware refinement 逻辑
191
  - OCR 运行在裁剪后的文本块图像上,而不是整页原图
192
  - OCR 封装使用的是 `llama.cpp` 的多模态路径,并采用 `OCR:` 提示
193
  - 修复阶段直接消费 `doc.segment`,所以糟糕的掩码会直接导致糟糕的清理结果
194
+ - 默认修复器是 `aot-inpainting`,`lama-manga` 仍可作为替代方案
195
  - 渲染前会对字体预测做归一化,让接近纯黑或纯白的颜色更稳定
196
 
197
  ## 推荐阅读
198
 
199
  ### 官方模型与项目参考
200
 
201
+ - [comic-text-and-bubble-detector model card](https://huggingface.co/ogkalu/comic-text-and-bubble-detector)
202
  - [PaddleOCR-VL-1.5 model card](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.5)
203
  - [Hugging Face Transformers 中的 PaddleOCR-VL 架构文档](https://huggingface.co/docs/transformers/en/model_doc/paddleocr_vl)
204
  - [comic-text-detector 仓库](https://github.com/dmMaze/comic-text-detector)
205
+ - [manga-image-translator 仓库](https://github.com/zyddnys/manga-image-translator)
206
+ - [YuzuMarker.FontDetection model card](https://huggingface.co/fffonion/yuzumarker-font-detection)
207
+ - [PP-DocLayoutV3 model card](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3)
208
  - [LaMa 仓库](https://github.com/advimman/lama)
209
  - [llama.cpp](https://github.com/ggml-org/llama.cpp)
210
 
docs/zh-CN/index.md CHANGED
@@ -494,7 +494,7 @@ hide:
494
  </div>
495
  <div class="kh-download-hero">
496
  <a class="kh-download-button" href="https://github.com/mayocream/koharu/releases/latest">
497
- 下载 Windows 版&nbsp;&nbsp;<span class="kh-download-button__version">0.40.1</span>
498
  </a>
499
  <div class="kh-download-hero__subtext">
500
  Koharu 免费且开源。
 
494
  </div>
495
  <div class="kh-download-hero">
496
  <a class="kh-download-button" href="https://github.com/mayocream/koharu/releases/latest">
497
+ 下载 Windows 版&nbsp;&nbsp;<span class="kh-download-button__version">0.42.1</span>
498
  </a>
499
  <div class="kh-download-hero__subtext">
500
  Koharu 免费且开源。