Photorealistic Style and Lighting Transfer using Gradient-Domain Optimization and Edge-Aware Filtering
This project implements a photorealistic style transfer system that combines semantic segmentation, depth estimation, gradient-domain editing, and edge-aware filtering to produce high-quality, photorealistic style transfers between images.
-
Install dependencies:
pip install -r requirements.txt -
Pipeline steps:
- Content Image + Style Image
- Semantic Segmentation (DeepLab)
- Depth Estimation (MiDaS)
- Gradient Editing for Lighting (basic Laplacian blending)
- Edge-Aware Smoothing (Guided Filter)
- Controlled Style Transfer (AdaIN limited by mask etc.)
- Output Photo
- Data Loading and Preprocessing
- Image loading with aspect ratio preservation
- Advanced data augmentation based on photorealistic style transfer research
- Efficient batch processing with uniform resizing
- Asynchronous image loading support for real-time applications
- M1/M2 Mac optimization with Metal Performance Shaders (MPS)
- Semantic Segmentation
- Depth Estimation
- Gradient Domain Editing
- Edge-Aware Filtering
- Style Transfer
We've implemented photography-inspired data augmentation techniques to enhance the robustness of our style transfer:
- Random Horizontal Flip: Simulates different camera angles
- Subtle Random Resized Crop: Simulates framing variations
- Small Affine Transformations: Simulates small camera movements
- Color Jittering: Simulates lighting and exposure variations
- Gaussian Noise: Simulates sensor noise and image imperfections
For detailed documentation about our augmentation approach, see:
- Data Augmentation Documentation - Implementation details and philosophy
- Data Augmentation Analysis - Analysis of subtle vs. exaggerated parameters
To visualize the effects of different augmentation techniques:
# View subtle augmentations (as used in production)
python scripts/test_augmentations.py --subtle
# View exaggerated augmentations (for demonstration purposes)
python scripts/test_augmentations.pyThe visualizations help illustrate why we've chosen subtle parameters for our augmentations, ensuring they enhance robustness while preserving photorealism.
Run the basic test script to verify the data loader functionality:
python scripts/test_data_loader.pyTo see all features of the data loader in action:
python scripts/demo_data_loader.pyAdditional options:
--image_size SIZE: Set custom image size (default: 512)--batch_size SIZE: Set batch size for testing (default: 4)--num_workers NUM: Set number of worker processes (default: 2)--no_augment: Disable data augmentation--paired: Use paired content-style images--benchmark: Run performance benchmarks for different configurations
To visualize the effects of different augmentation techniques:
python scripts/test_augmentations.pyOptions:
--image_path PATH: Specify a custom image to augment--size SIZE: Set the target image size (default: 512)
src/: Source codedata_loader.py: Image loading and preprocessingsegmentation/: Semantic segmentation modelsdepth/: Depth estimation modelsgradient_domain/: Gradient domain manipulationedge_aware/: Edge-aware filteringstyle_transfer/: Neural style transferutils/: Utility functions
scripts/: Helper scripts for testing and demonstrationdata/: Data directorycontent/: Content imagesstyle/: Style imagesresults/: Output results
models/: Pre-trained model weightsnotebooks/: Jupyter notebooks for experimentationdocs/: Documentation files
This project includes optimizations for Apple Silicon (M1/M2) using PyTorch's Metal Performance Shaders (MPS). To ensure optimal performance:
-
Install PyTorch with MPS support:
pip install torch torchvision torchaudio -
The data loader automatically detects MPS availability and adjusts worker count accordingly.
-
For best performance on M1/M2, use batch sizes between 2-8 with 1-2 worker processes.