A computer vision tool that automatically processes .cbz and .pdf files, detects individual comic panels using AI, and extracts them into a mobile-optimized .cbz file.
Instead of struggling with a clunky PDF on a phone screen, this tool converts unmapped, static pages into a panel-by-panel reading experience compatible with standard mobile readers like CDisplayEx, Perfect Viewer, or Panels.
The OpenCV detection algorithm is specifically tuned to handle the hard stuff: narrow gutters, aged paper, and the heavy ink bleed of vintage comic scans.
How it works:
The engine uses OpenCV to convert each page to grayscale and applies an Otsu/Adaptive binary threshold to isolate the ink from the paper. It then uses morphological closing to bridge gaps in faded panel borders, and contour detection (cv2.findContours using RETR_EXTERNAL) to draw bounding boxes while intentionally ignoring internal dialogue balloons. Finally, it filters out noise based on area and aspect ratios, discards overlapping regions via Intersection-over-Union Non-Maximum Suppression (IoU-NMS), and calculates the final reading order using DPI-independent row clustering.
Where it might fail (Please read):
Because this relies on visual heuristics rather than publisher-provided metadata, it may not work in some cases. You may experience incorrect crops or missed panels under the following conditions:
- Overlapping Panels / Broken Gutters: If a character's arm reaches outside a panel and breaks the gutter line, the algorithm may merge two panels together.
- Non-Rectangular / Splash Pages: Circular panels, extreme diagonals, or chaotic splash pages without clear borders will likely confuse the bounding box logic.
- Zero-Gutter / Full Bleed: If the page has no gutters at all (the art goes entirely to the edge of the page), the algorithm cannot slice it.
- Floating Text: Text or dialogue balloons that float in the absolute white space outside of a bordered panel may be ignored by the cropper.
This repository contains three different ways to run the extraction engine: a pre-compiled Windows executable, a Python script, and a Web-Based local server.
desktop_app.py: A native Windows GUI application that runs the conversion engine locally usingtkinter.dist/: Contains the compiled.exestandalone application (if built with PyInstaller).build/: Temporary compilation files generated by PyInstaller.backend/: A Python/FastAPI server acting as the web-based conversion engine.frontend/: A Vite + React application providing a web UI for the conversion engine.runtime/: An auto-generated temporary storage folder. The web backend extracts pages here during the conversion process.
To ensure the OpenCV matrix calculations and PyInstaller build processes execute correctly without dependency conflicts, this project requires specific library versions:
- Python: 3.12.x
- Node.js: v18+ (Only required for Option 2)
- OpenCV:
opencv-python==4.9.0.80(Newer versions may conflict with NumPy 1.x) - NumPy:
numpy<2(Crucial: OpenCV 4.9 requires NumPy 1.x) - PyMuPDF:
PyMuPDF(Latest stable)
If you do not want to install Python, Node.js, or any background dependencies, you can simply download and run the pre-built Windows application.
- Navigate to the
dist/folder in this repository. - Click on
Comic-Panel-Extractor_Win64.exe. - Click the Download raw file button (the download icon on the right side) to save it to your computer.
- Double-click the downloaded
.exefile to launch the converter instantly.
This is a great way to use the converter without starting local web servers, assuming you have an Anaconda/Python environment set up.
- Open your terminal or Anaconda Prompt.
- Install the strict versions required:
pip install PyMuPDF opencv-python==4.9.0.80 "numpy<2"
- Navigate to the
Comic-Panel-Extractorfolder. - Run the application:
python desktop_app.py
- A Windows GUI will appear. Click Select Comic File, choose your
.pdfor.cbz, and select where to save the new mobile-optimized.cbzfile.
If you prefer to run the converter through your web browser, you can spin up the local servers.
- Install the backend dependencies:
pip install fastapi uvicorn python-multipart PyMuPDF opencv-python==4.9.0.80 "numpy<2"
You must start both servers simultaneously in separate terminals.
Terminal 1: Start the Backend (From the root folder)
python backend/main.pyTerminal 2: Start the Frontend (From the frontend folder)
npm install
npm run devAccessing the UI:
Open your web browser and navigate to http://localhost:5173. Upload your file, and the browser will automatically download the newly generated _Mobile.cbz when the backend finishes processing.
Since this extractor is specifically tuned to handle the aged paper, narrow gutters, and ink bleed of vintage scans, it pairs perfectly with historical archives.
If you want to test the tool, we recommend downloading Public Domain golden-age comics from these fantastic legal preservation archives:
- Digital Comic Museum: A strictly moderated archive of public domain Golden Age comics. (Requires a free account to download).
- Comic Book Plus: Another massive, legally vetted archive of public domain comics, comic strips, and pulps.
- Internet Archive (Comics Collection): A vast library of historical digital materials. (Note: While many items are public domain, users should verify the copyright status of individual uploads).
- The Luminist Archives: A great historical preservation project featuring vintage periodicals and comics.
If you use this software or the custom OpenCV panel detection algorithm in your work, please cite it as follows:
Text: Karim, ME. (2026). AI Comic Panel Extractor. GitHub. https://github.com/ehsanx/Comic-Panel-Extractor
BibTeX:
@software{LocalComic-Panel-Extractor2026,
author = {Karim, ME.},
title = {AI Comic Panel Extractor},
year = {2026},
publisher = {GitHub},
url = {[https://github.com/ehsanx/Comic-Panel-Extractor](https://github.com/ehsanx/Comic-Panel-Extractor)}
}This software is provided "AS IS", without warranty of any kind, express or implied. The developer assumes no responsibility for errors, omissions, or damages resulting from the use of this software. This tool is intended for use with files you legally own or those in the public domain. Please respect publisher copyrights.