Skip to content

๐ŸŽจ AI-powered comic book analysis with frame detection, interpolation, and animation creation using RIFE, FILM, and YOLO models

License

Notifications You must be signed in to change notification settings

pr1m8/comicframes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ComicFrames ๐ŸŽจ๐Ÿค–

Version Python License: MIT Development Status GitHub stars GitHub forks

๐Ÿš€ The beginning of bringing comics to life through AI-powered animation

ComicFrames is a foundational Python package for comic book analysis and the first step toward creating animated storytelling experiences. Starting with robust frame detection using OpenCV and computer vision, this project is evolving into a complete animation pipeline powered by state-of-the-art neural networks like RIFE, FILM, and YOLO.

๐ŸŽฏ Vision: From Static to Animated

This project represents the starting point of a larger vision: transforming static comic books into dynamic, animated experiences. We're building the infrastructure and tools that will eventually power:

  • ๐ŸŽฌ Seamless frame interpolation for smooth panel transitions
  • ๐ŸŽญ Character animation within comic panels
  • ๐Ÿ’ฌ Speech bubble dynamics and text-to-speech integration
  • ๐ŸŽจ Style-aware animation preserving artistic integrity
  • ๐ŸŽฎ Interactive comic experiences with user-driven pacing

๐Ÿ› ๏ธ Current Implementation Status

โœ… Production Ready (v0.1.0)

  • ๐Ÿ“– PDF Processing: High-quality comic book to image conversion with PyMuPDF
  • ๐Ÿ” OpenCV Frame Detection: Two robust methods (threshold & Canny edge detection)
  • ๐Ÿ—๏ธ Modular Architecture: Clean separation with processing pipelines and caching
  • ๐Ÿ–ฅ๏ธ CLI Tools: 5 command-line utilities for batch processing
  • โšก Smart Caching: Multi-level cache system with TTL and performance metrics
  • ๐Ÿ›ก๏ธ Type Safety: Complete type annotations and runtime validation

๐Ÿ”„ In Development (Neural Network Integration)

  • ๐ŸŽฌ RIFE Integration: Real-time frame interpolation (models included, implementation ongoing)
  • ๐ŸŽญ FILM Integration: Google's large motion interpolation (setup complete, API in progress)
  • ๐Ÿ” YOLO Detection: Speech bubble and character detection (config ready, training needed)
  • ๐Ÿค— Hugging Face Pipeline: Model hub integration for community models

๐ŸŽฏ Future Milestones

  • ๐ŸŽจ Animation Export: MP4/GIF generation from interpolated frames
  • ๐Ÿ’ฌ Text Analysis: OCR and speech bubble text extraction
  • ๐ŸŽฎ Interactive Viewer: Web-based comic animation player
  • ๐ŸŽญ Character Tracking: Persistent character identification across panels

๐Ÿง  Computer Vision & AI Foundation

Current OpenCV Implementation

ComicFrames currently uses proven computer vision techniques for robust frame detection:

# Threshold-based detection (clean, geometric panels)
_, binary = cv2.threshold(gray, 225, 255, cv2.THRESH_BINARY_INV)
contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

# Canny edge detection (complex, artistic layouts)  
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
edges = cv2.Canny(blurred, 10, 200)
contours = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

Neural Network Models (Integration Layer Ready)

The architecture is designed for easy model swapping once neural implementations are complete:

  • ๐ŸŽฌ RIFE v4.6: 130+ FPS frame interpolation (PyTorch models downloaded)
  • ๐ŸŽญ FILM: TensorFlow-based large motion interpolation (Google Research)
  • ๐Ÿ” YOLOv3: Real-time object detection (config files ready)
  • ๐Ÿค— Hugging Face: Community model integration via ModelFactory

Technical Architecture

  • ๐Ÿ”ง Plugin System: Easy model registration and switching
  • โšก Caching: Intelligent model loading and result caching
  • ๐Ÿ“Š Metrics: Performance monitoring for all processing stages
  • ๐Ÿ—๏ธ Pipelines: Chain OpenCV โ†’ Neural Network โ†’ Animation export

๐ŸŽฌ Animation Pipeline Architecture

Stage 1: Foundation (โœ… Complete)

from comicframes import pdf_to_images, detect_frames

# Convert comic PDF to high-quality page images
pdf_to_images("watchmen.pdf", output_dir="./pages")

# Extract individual panels using OpenCV
frames_detected = detect_frames("./pages/page_1.png", method="threshold")

Stage 2: Neural Network Integration (๐Ÿ”„ In Progress)

from comicframes import ModelFactory, ProcessingPipeline

# Create interpolation pipeline (implementation ongoing)
rife_model = ModelFactory.create_model("rife_v4.6")
film_model = ModelFactory.create_model("film_net") 

# Chain frame detection โ†’ interpolation โ†’ animation
pipeline = ProcessingPipeline("comic_animation")
pipeline.add_stage(PDFProcessor())
pipeline.add_stage(FrameProcessor())
pipeline.add_stage(InterpolationProcessor(rife_model))

result = pipeline.process("comic.pdf")

Stage 3: Advanced Animation (๐ŸŽฏ Planned)

# Future API for complete animation generation
animator = ComicAnimator()
animator.load_comic("comic.pdf")
animator.set_transition_style("smooth")  # smooth, cinematic, dynamic
animator.add_speech_timing("auto")       # auto, manual, voice-sync
animated_comic = animator.render(output_format="mp4")

๐Ÿ”— Neural Network Models & Research

๐ŸŽฌ Frame Interpolation Research

  • RIFE (ECCV 2022): Real-Time Intermediate Flow Estimation

    • โšก 130+ FPS on RTX 3090
    • ๐ŸŽฏ State-of-the-art interpolation quality
    • โœ… Models Downloaded (external_models/ECCV2022-RIFE/)
  • FILM (Google Research): Frame Interpolation for Large Motion

    • ๐ŸŽญ Large motion handling for dramatic panel transitions
    • ๐Ÿง  TensorFlow implementation with pre-trained models
    • โœ… Repository Integrated (external_models/frame-interpolation/)

๐Ÿ” Object Detection & Analysis

  • YOLOv3: Real-time object detection
    • ๐Ÿ’ฌ Speech bubble detection and text region identification
    • ๐Ÿ‘ฅ Character detection for tracking across panels
    • โœ… Config Ready (external_models/Yolo_Model/)

๐Ÿค— Hugging Face Ecosystem

# Future community model integration
from comicframes import ModelFactory

# Load community-trained comic-specific models
speech_detector = ModelFactory.create_model("huggingface/comic-speech-detection")
character_classifier = ModelFactory.create_model("huggingface/comic-character-recognition")
style_interpolator = ModelFactory.create_model("huggingface/comic-style-preserving-interpolation")

Installation

๐Ÿ“ฆ PyPI Status: Package not yet published to PyPI. Install from source for now.

๐Ÿš€ Quick Setup (Development)

# Clone the repository
git clone https://github.com/pr1m8/comicframes.git
cd comicframes

# Install with uv (recommended)
uv pip install -e .

# Or install with pip
pip install -e .

๐Ÿ“‹ Dependencies

# Core dependencies (automatically installed)
pymupdf>=1.23.0     # PDF processing
opencv-python>=4.5.0  # Computer vision
numpy>=1.21.0       # Numerical operations  
pillow>=8.0.0       # Image manipulation

๐Ÿ”ฎ Future PyPI Installation

# Coming soon - when package is published
uv pip install comicframes
pip install comicframes

Usage

๐Ÿš€ Quick Start: From Comic to Animated Frames

Step 1: Basic Frame Detection (Works Now)

from comicframes import pdf_to_images, detect_frames

# Extract pages from comic PDF
pdf_to_images("watchmen.pdf", output_base_dir="./pages") 

# Detect panels using OpenCV computer vision
total_frames = detect_frames("./pages/page_1.png", 
                           min_width=100, 
                           detection_method="threshold")

print(f"Detected {total_frames} panels ready for animation")

Step 2: Advanced Processing Pipeline

from comicframes.processing import PDFProcessor, FrameProcessor
from comicframes.core import ProcessingPipeline

# Create a complete comic processing pipeline
pipeline = ProcessingPipeline("comic_analysis")
pipeline.add_stage(PDFProcessor())      # PDF โ†’ Images
pipeline.add_stage(FrameProcessor())    # Images โ†’ Panel detection

# Process entire comic book
result = pipeline.process("comic.pdf")
print(f"Pipeline processed {len(result.data)} pages")

Step 3: Performance & Caching

from comicframes import Settings, get_cache_manager

# Configure for optimal performance
settings = Settings(
    min_frame_width=75,      # Adjust for comic style
    min_frame_height=100,    # Filter out small panels
    enable_cache=True        # Cache processing results
)

# Monitor processing performance
cache = get_cache_manager()
stats = cache.get_cache_stats()
print(f"Cache hit ratio: {stats.hit_ratio:.2%}")

Step 4: Neural Network Integration (Coming Soon)

# Future API - Neural network enhanced processing
from comicframes import ModelFactory
from comicframes.models import RIFEInterpolator, FILMInterpolator

# Load state-of-the-art interpolation models
rife = ModelFactory.create_model("rife_v4.6")      # 130+ FPS interpolation  
film = ModelFactory.create_model("film_net")       # Large motion handling

# Create smooth panel transitions
interpolated_frames = rife.interpolate_between_panels(
    panel_1="frame_001.png",
    panel_2="frame_002.png",
    transition_frames=8,        # 8 intermediate frames
    preserve_style=True         # Maintain comic art style
)

Command Line Interface

Convert PDF to Images

# Basic usage
comicframes-pdf comic.pdf

# Specify output directory
comicframes-pdf comic.pdf --output-dir ./my_output

# Skip automatic frame detection
comicframes-pdf comic.pdf --no-frame-detection

Extract Frames from Images

# Basic usage
comicframes-extract ./pages ./output

# With custom minimum frame sizes
comicframes-extract ./pages ./output --min-width 100 --min-height 150

New Commands

# Complete processing pipeline
comicframes-pipeline comic.pdf --output-dir ./output --model opencv_contours

# Cache management
comicframes-cache stats
comicframes-cache clear --type processing
comicframes-cache cleanup

# Model management
comicframes-models list
comicframes-models info opencv_contours

Project Structure

comicframes/                    # Clean, organized root
โ”œโ”€โ”€ src/comicframes/           # Main package source
โ”‚   โ”œโ”€โ”€ config/               # Configuration management
โ”‚   โ”œโ”€โ”€ cache/                # Caching system
โ”‚   โ”œโ”€โ”€ core/                 # Core abstractions
โ”‚   โ”œโ”€โ”€ models/               # Model implementations
โ”‚   โ”œโ”€โ”€ processing/           # High-level processors
โ”‚   โ”œโ”€โ”€ pdf_processor.py      # Legacy compatibility
โ”‚   โ”œโ”€โ”€ frame_detector.py     # Legacy compatibility
โ”‚   โ””โ”€โ”€ cli.py               # Command-line interface
โ”œโ”€โ”€ external_models/          # External model integrations
โ”‚   โ”œโ”€โ”€ ECCV2022-RIFE/       # RIFE frame interpolation
โ”‚   โ”œโ”€โ”€ frame-interpolation/  # Google FILM models
โ”‚   โ””โ”€โ”€ Yolo_Model/          # YOLO object detection
โ”œโ”€โ”€ data_samples/             # Sample data and tests
โ”‚   โ”œโ”€โ”€ Data/                # Sample comic data
โ”‚   โ””โ”€โ”€ test_data/           # Test files
โ”œโ”€โ”€ examples/                 # Usage examples
โ”œโ”€โ”€ tests/                    # Test suite
โ”œโ”€โ”€ docs/                     # Documentation
โ””โ”€โ”€ scripts/                  # Utility scripts

Development

Setup Development Environment

# Install development dependencies
uv pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/
isort src/

# Lint code
flake8 src/

Building the Package

# Build wheel and source distribution
python -m build

# Install locally
uv pip install dist/comicframes-*.whl

๐Ÿ—บ๏ธ Development Roadmap: Building the Animation Future

๐Ÿ“ˆ Phase 1: Foundation โœ… (v0.1.0 - Current)

Status: Production Ready - Solid computer vision foundation

  • โœ… PDF Processing: PyMuPDF integration for high-quality page extraction
  • โœ… OpenCV Frame Detection: Threshold & Canny edge detection algorithms
  • โœ… Processing Architecture: Modular pipeline system with caching
  • โœ… CLI Tools: 5 command-line utilities for batch processing
  • โœ… Developer Experience: Type safety, documentation, testing framework

๐Ÿš€ Phase 2: Neural Network Integration ๐Ÿ”„ (v0.2.0 - Q1 2024)

Status: In Progress - Models downloaded, API implementation ongoing

  • ๐Ÿ”„ RIFE Implementation: Complete PyTorch model integration (models ready)
  • ๐Ÿ”„ FILM Implementation: TensorFlow model wrapper development
  • ๐Ÿ”„ YOLO Integration: Object detection for speech bubbles and characters
  • ๐Ÿ”„ Model Management: Enhanced ModelFactory with automatic downloading
  • ๐Ÿ”„ Performance Optimization: GPU acceleration and batching support

๐ŸŽฌ Phase 3: Animation Generation ๐ŸŽฏ (v0.3.0 - Q2 2024)

Status: Planned - Animation pipeline and export capabilities

  • ๐ŸŽฏ Frame Interpolation: Smooth transitions between comic panels
  • ๐ŸŽฏ Animation Export: MP4/GIF generation with customizable timing
  • ๐ŸŽฏ Transition Effects: Multiple animation styles (smooth, cinematic, dynamic)
  • ๐ŸŽฏ Batch Animation: Process entire comic books into animated sequences
  • ๐ŸŽฏ Quality Controls: Resolution, frame rate, and compression options

๐ŸŽฎ Phase 4: Interactive Experiences ๐Ÿ”ฎ (v0.4.0 - Q3 2024)

Status: Future - Advanced features and user interfaces

  • ๐Ÿ”ฎ Web Interface: Browser-based comic animation viewer
  • ๐Ÿ”ฎ Speech Integration: Text-to-speech with character voice synthesis
  • ๐Ÿ”ฎ Character Tracking: Persistent character identification across panels
  • ๐Ÿ”ฎ Style Transfer: Artistic style preservation during animation
  • ๐Ÿ”ฎ Interactive Timing: User-controlled pacing and panel transitions

๐ŸŒŸ Phase 5: AI-Enhanced Storytelling ๐Ÿ”ฎ (v1.0.0 - Future)

Status: Visionary - Advanced AI for narrative understanding

  • ๐Ÿ”ฎ Story Analysis: Automated narrative flow detection
  • ๐Ÿ”ฎ Emotion Detection: Character emotional state recognition
  • ๐Ÿ”ฎ Scene Understanding: Context-aware animation decisions
  • ๐Ÿ”ฎ Multi-language: Global text extraction and voice synthesis
  • ๐Ÿ”ฎ Community Models: Hugging Face Hub integration for specialized models

๐Ÿท๏ธ Tags

computer-vision comic-analysis frame-detection animation ai machine-learning opencv yolo rife film huggingface python cli processing-pipeline caching

๐Ÿค Contributing

We welcome contributions! ComicFrames is designed to be easily extensible:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Add your processor/model: Follow our plugin architecture
  4. Add tests: Ensure your code is well-tested
  5. Submit a PR: We'll review and merge

See our Contributing Guide for detailed instructions.

๐Ÿ“š Citation

If you use ComicFrames in your research, please cite:

@software{comicframes2024,
  title={ComicFrames: AI-Powered Comic Book Analysis and Animation},
  author={ComicFrames Project},
  year={2024},
  url={https://github.com/pr1m8/comicframes},
  version={0.1.0},
  note={Foundation for neural network-based comic animation}
}

๐Ÿ”— Related Projects

๐Ÿ“Š Stats

GitHub Last Commit GitHub Issues GitHub Pull Requests GitHub Contributors

License

MIT License - see the LICENSE file for details.