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|
|
|
|
|
|
|
|
|
| 1 |
+
```markdown
|
| 2 |
+
# DeepPanel: Comic Panel Extractor (Keras Model)
|
| 3 |
+
|
| 4 |
+
**Model Card** β’ [Hugging Face Repo](https://huggingface.co/codeShare/comic-panel-extract) β’ [Download `.keras` file](https://huggingface.co/codeShare/comic-panel-extract/blob/main/deeppanel_model.keras)
|
| 5 |
+
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
## π Overview
|
| 9 |
+
|
| 10 |
+
**`deeppanel_model.keras`** is a fully trained **TensorFlow/Keras** model for **automatic comic panel extraction**.
|
| 11 |
+
|
| 12 |
+
It takes a full comic book page (or any illustrated page) as input and outputs a **binary mask** that highlights every individual panel. The post-processing code then uses OpenCV to crop each detected panel into its own clean image.
|
| 13 |
+
|
| 14 |
+
This model was originally developed as **DeepPanel** and has been retrained/fine-tuned specifically for Western and manga-style comics.
|
| 15 |
+
|
| 16 |
+
### What it does
|
| 17 |
+
- Input: One comic page (JPG/PNG)
|
| 18 |
+
- Output: Mask of panel regions β cropped panel images
|
| 19 |
+
- Works on **any resolution** (automatically resized internally to 256Γ256 for inference, then scaled back)
|
| 20 |
+
- Handles multi-panel pages, overlapping speech bubbles, and complex layouts
|
| 21 |
+
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
## π¦ Model File
|
| 25 |
+
|
| 26 |
+
| File | Size | Format | Description |
|
| 27 |
+
|-------------------------|----------|-----------------|--------------------------------------|
|
| 28 |
+
| `deeppanel_model.keras` | ~XX MB | Keras v3 | Full model (architecture + weights) |
|
| 29 |
+
|
| 30 |
+
**Direct download link:**
|
| 31 |
+
```bash
|
| 32 |
+
https://huggingface.co/codeShare/comic-panel-extract/resolve/main/deeppanel_model.keras
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
-----
|
| 36 |
+
|
| 37 |
+
## π Quick Start (Colab / Local)
|
| 38 |
+
|
| 39 |
+
### 1. Install dependencies
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
pip install tensorflow opencv-python-headless numpy tqdm huggingface_hub
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
### 2. Download + Load the model
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
from huggingface_hub import hf_hub_download
|
| 49 |
+
import tensorflow as tf
|
| 50 |
+
|
| 51 |
+
model_path = hf_hub_download(
|
| 52 |
+
repo_id="codeShare/comic-panel-extract",
|
| 53 |
+
filename="deeppanel_model.keras"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
model = tf.keras.models.load_model(model_path)
|
| 57 |
+
print("β
DeepPanel model loaded!")
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### 3. Full extraction pipeline (copy-paste ready)
|
| 61 |
+
|
| 62 |
+
See the exact code used in the [original Colab notebook](https://colab.research.google.com/...) (link will be added once public).
|
| 63 |
+
|
| 64 |
+
Or use the **minimal working example** below:
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
import cv2
|
| 68 |
+
import numpy as np
|
| 69 |
+
from huggingface_hub import hf_hub_download
|
| 70 |
+
import tensorflow as tf
|
| 71 |
+
import os
|
| 72 |
+
from tqdm import tqdm
|
| 73 |
+
|
| 74 |
+
# Load model once
|
| 75 |
+
model_path = hf_hub_download(repo_id="codeShare/comic-panel-extract", filename="deeppanel_model.keras")
|
| 76 |
+
model = tf.keras.models.load_model(model_path)
|
| 77 |
+
|
| 78 |
+
def extract_panels_from_page(image_path, output_folder="panels"):
|
| 79 |
+
os.makedirs(output_folder, exist_ok=True)
|
| 80 |
+
|
| 81 |
+
# Preprocess
|
| 82 |
+
img = cv2.imread(image_path)
|
| 83 |
+
original_shape = img.shape[:2]
|
| 84 |
+
resized = cv2.resize(cv2.cvtColor(img, cv2.COLOR_BGR2RGB), (256, 256)) / 255.0
|
| 85 |
+
input_tensor = np.expand_dims(resized, axis=0).astype(np.float32)
|
| 86 |
+
|
| 87 |
+
# Predict mask
|
| 88 |
+
mask_pred = model.predict(input_tensor, verbose=0)[0]
|
| 89 |
+
if len(mask_pred.shape) == 3 and mask_pred.shape[-1] == 1:
|
| 90 |
+
mask_pred = mask_pred.squeeze(axis=-1)
|
| 91 |
+
|
| 92 |
+
# Post-process
|
| 93 |
+
mask = cv2.resize((mask_pred > 0.5).astype(np.uint8) * 255, (original_shape[1], original_shape[0]))
|
| 94 |
+
contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
| 95 |
+
|
| 96 |
+
page_name = os.path.splitext(os.path.basename(image_path))[0]
|
| 97 |
+
count = 0
|
| 98 |
+
for contour in contours:
|
| 99 |
+
x, y, w, h = cv2.boundingRect(contour)
|
| 100 |
+
if w < 30 or h < 30:
|
| 101 |
+
continue
|
| 102 |
+
panel = img[y:y+h, x:x+w]
|
| 103 |
+
cv2.imwrite(f"{output_folder}/{page_name}_panel_{count:02d}.jpg", panel)
|
| 104 |
+
count += 1
|
| 105 |
+
|
| 106 |
+
return count
|
| 107 |
+
|
| 108 |
+
# Example usage
|
| 109 |
+
panels_extracted = extract_panels_from_page("my_comic_page.jpg", "extracted_panels")
|
| 110 |
+
print(f"Extracted {panels_extracted} panels!")
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
-----
|
| 114 |
+
|
| 115 |
+
## π Related Resources
|
| 116 |
+
|
| 117 |
+
- **GitHub Repository** (full training + inference code + dataset scripts):
|
| 118 |
+
β *Coming soon* (will be linked here once published)
|
| 119 |
+
- **Google Colab Notebook** (ready-to-run version with your `comics.zip`):
|
| 120 |
+
[Open in Colab](https://colab.research.google.com/) *(paste the full notebook code from our previous conversation)*
|
| 121 |
+
- **Dataset used for training**: Custom comic panel dataset (Western + Manga)
|
| 122 |
+
|
| 123 |
+
-----
|
| 124 |
+
|
| 125 |
+
## π― Intended Use Cases
|
| 126 |
+
|
| 127 |
+
- Bulk comic/manga digitization pipelines
|
| 128 |
+
- Preparing training data for AI comic colorizers, inpainters, or speech bubble removers
|
| 129 |
+
- Building web apps that auto-split comic pages into panels
|
| 130 |
+
- Research on layout analysis for illustrated books
|
| 131 |
+
|
| 132 |
+
**Works best on**:
|
| 133 |
+
|
| 134 |
+
- Clear black-and-white or color comics
|
| 135 |
+
- Standard Western comic pages and Japanese manga
|
| 136 |
+
|
| 137 |
+
**Limitations**:
|
| 138 |
+
|
| 139 |
+
- Very low-resolution or heavily compressed scans may give poorer results
|
| 140 |
+
- Extremely artistic/experimental layouts (full-bleed splash pages) may need manual correction
|
| 141 |
+
|
| 142 |
+
-----
|
| 143 |
+
|
| 144 |
+
## π οΈ Technical Details
|
| 145 |
+
|
| 146 |
+
- **Framework**: TensorFlow 2.x + Keras 3
|
| 147 |
+
- **Architecture**: U-Net style (encoder-decoder) optimized for segmentation
|
| 148 |
+
- **Input size during inference**: 256Γ256 (automatically resized)
|
| 149 |
+
- **Output**: Single-channel probability mask
|
| 150 |
+
- **License**: MIT (model weights + code)
|
| 151 |
+
|
| 152 |
+
-----
|
| 153 |
+
|
| 154 |
+
## π Citation
|
| 155 |
+
|
| 156 |
+
If you use this model in your project, please cite:
|
| 157 |
+
|
| 158 |
+
```bibtex
|
| 159 |
+
@misc{deeppanel-comic-extractor-2026,
|
| 160 |
+
title = {DeepPanel: Comic Panel Extractor},
|
| 161 |
+
author = {codeShare},
|
| 162 |
+
year = {2026},
|
| 163 |
+
howpublished = {\url{https://huggingface.co/codeShare/comic-panel-extract}},
|
| 164 |
+
note = {Keras model for automatic comic panel detection}
|
| 165 |
+
}
|
| 166 |
+
```
|