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