Available Inpainting Methods
AOT (Aggregated Contextual Transformations)
AOT (Aggregated Contextual Transformations)
Overview
Deep learning inpainting model from manga-image-translator. Good balance of speed and quality.Configuration
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
device | selector | auto | Processing device (cuda/cpu/mps) |
inpaint_size | int | 2048 | Maximum inpainting resolution |
precision | selector | fp32 | Model precision (fp32/fp16/bf16) |
Features
- GPU Accelerated: Fast processing with CUDA
- High Quality: Good reconstruction of complex backgrounds
- Context-Aware: Uses surrounding context for inpainting
- Mixed Precision: Support for fp16/bf16 to save VRAM
Model Files
data/models/aot_inpainter.ckpt
Performance Notes
- Higher
inpaint_size= better quality but more VRAM - Use fp16 precision to reduce memory usage
- Automatic CUDA OOM handling with CPU fallback
LAMA (Large Mask Inpainting)
LAMA (Large Mask Inpainting)
Overview
State-of-the-art inpainting model from advimman/lama. Fine-tuned for manga.Configuration
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
device | selector | auto | Processing device |
inpaint_size | int | 2048 | Max resolution |
precision | selector | fp32 | Model precision |
Available Variants
- lama_large_512px: Standard LAMA model
- lama_mpe: Manga-optimized fine-tuned version
Features
- Excellent Quality: Best results for complex backgrounds
- Large Mask Support: Handles large text regions well
- Fine-tuned: Optimized for manga/comic content
- FFC Architecture: Uses Fast Fourier Convolution
Model Files
data/models/lama_large_512px.ckptdata/models/lama_mpe.ckpt(manga-optimized)
When to Use
- Complex textured backgrounds
- Large text regions
- Maximum quality needed
- VRAM is not a constraint
PatchMatch
PatchMatch
Overview
Non-deep-learning algorithm based on PyPatchMatch. Same algorithm as Photoshop’s Content-Aware Fill.Configuration
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
patch_size | int | 15 | Patch size for matching |
Features
- No GPU Required: Pure CPU algorithm
- Fast: Quick processing for small regions
- No Model Files: Doesn’t require downloading models
- Deterministic: Reproducible results
Implementation Details
Platform Support
- Windows:
data/libs/patchmatch_inpaint.dll - macOS:
data/libs/macos_libpatchmatch_inpaint.dylib - Linux:
data/libs/libpatchmatch.so
When to Use
- Simple backgrounds
- Limited GPU memory
- Small text regions
- No model downloads desired
Limitations
- Less effective on complex textures
- May produce artifacts on large regions
- Slower than GPU methods for large images
Inpainting Strategies
Block-based Inpainting
Inpaint each text block individually:- More efficient use of resolution
- Better for scattered text
- Lower memory usage
Full Image Inpainting
Inpaint entire image at once:- Better context across regions
- More coherent results
- Better for dense text
Usage Example
RGBA Image Support
Inpainting automatically handles transparency:- Separates RGB and alpha channels
- Inpaints RGB only
- Reconstructs alpha based on surroundings
- Returns RGBA result
Memory Management
Automatic CUDA OOM Handling
The inpainter automatically handles out-of-memory errors:- First OOM: Clear CUDA cache and retry
- Second OOM: Switch to CPU temporarily
- Restore GPU after completion
Reducing Memory Usage
Advanced Configuration
Precision Modes
| Precision | VRAM Usage | Speed | Quality | Notes |
|---|---|---|---|---|
| fp32 | 100% | Baseline | Best | Default |
| fp16 | ~50% | Faster | Excellent | CUDA only |
| bf16 | ~50% | Faster | Excellent | Ampere+ GPUs |
Custom Inpainting Resolution
Mask Preprocessing
Balloon Detection Integration
Automatic balloon detection for better inpainting:Choosing an Inpainting Method
| Scenario | Recommended Method | Notes |
|---|---|---|
| Best quality | LAMA (lama_mpe) | Manga-optimized |
| Balanced | AOT | Good speed/quality |
| No GPU | PatchMatch | CPU-only option |
| Low VRAM | AOT with fp16 | Memory efficient |
| Large regions | LAMA | Best for big masks |
| Simple backgrounds | PatchMatch | Fast and effective |
| Complex textures | LAMA | Best reconstruction |
Custom Inpainting Models
To add custom inpainting models:Performance Benchmarks
Speed (1024x1024 image)
| Method | GPU (RTX 3090) | CPU (i9) |
|---|---|---|
| AOT | ~0.5s | ~8s |
| LAMA | ~0.8s | ~15s |
| PatchMatch | N/A | ~3s |
Quality Ranking
- LAMA (lama_mpe): Best overall
- LAMA (lama_large_512px): Excellent
- AOT: Very good
- PatchMatch: Good for simple cases
Troubleshooting
CUDA Out of Memory
Poor Quality Results
- Increase resolution:
inpaint_size = 2048 - Try LAMA: Best quality model
- Dilate mask: Expand coverage slightly
- Use full image mode:
inpaint_by_block = False
Slow Performance
- Use GPU: Set
device='cuda' - Lower resolution: Reduce
inpaint_size - Use fp16: Faster than fp32
- Try AOT: Faster than LAMA
