6 Commits
Author SHA1 Message Date
sumitchatterjee13 b38050001b Fix version consistency: Update all version references to 1.1.8 2025-10-05 22:39:36 +11:00
sumitchatterjee13 9f765d9c00 Bug fixes and worked more on Debevec algorithm, updated Documentation 2025-10-05 22:16:26 +11:00
sumitchatterjee13 3162cc3adc Bug fixed with detail injection where exposure compensation was wrongly applied and killing hdr data 2025-10-04 09:45:52 +10:00
sumitchatterjee13 c14ab801cc Updated documentation 2025-10-04 01:14:58 +10:00
sumitchatterjee13 ce6212079f Made the debevec algorithm working and added new algorithm Detail_injection 2025-10-04 00:53:37 +10:00
sumitchatterjee13 4e5a1be5fb Improve HDRExportNode path handling logic
- Added robust _get_comfyui_output_directory() method with multiple fallbacks
- Improved path handling to support:
  - Empty string → default ComfyUI/output directory
  - Paths starting with '/' → subdirectories in output (e.g., /Test → output/Test)
  - Regular paths → absolute/relative custom paths
- Enhanced verification logging to show min/max range and file stats
- Added HDR pixel detection in input logging
- Updated tooltips to reflect new path behavior

Based on LinearEXRExport node improvements
2025-09-24 01:48:38 +10:00
6 changed files with 1940 additions and 166 deletions
+159
View File
@@ -7,7 +7,166 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.1.8] - 2025-10-02
### Changed
- **⚙️ Default exposure_adjust changed to 0.0** - No additional exposure adjustment by default
- Previous default: 1.0 (+1 stop brighter)
- New default: 0.0 (use automatic brightness compensation only)
- Applies to both 3-stop and 5-stop processors
- Users can still adjust manually if needed (+/- 5 stops range)
## [1.1.7] - 2025-10-02
### Changed
- **🎨 Improved highlight/shadow mask generation** - Smoother, more gradual transitions
- **Wider threshold ranges**: Highlight masks start earlier (0.6 vs 0.7), cover more area
- **21×21 Gaussian smoothing**: Applied to all masks with sigma=7.0 for very gradual feathering
- **No image blurring**: Smooths the blending masks, not the image itself
- **Eliminates sharp cutoffs**: Gradual transitions prevent visible blend boundaries
- **Consistent across highlights and shadows**: Both use improved mask generation
### Removed
- **Removed HDR region post-processing blur** - Caused unwanted image blurring
### Technical Details
- Masks now use both wider Hermite interpolation ranges AND Gaussian smoothing
- 21×21 kernel with sigma=7.0 creates very soft feathering (14 pixel transition zone)
- Affects blending behavior, not final image sharpness
## [1.1.6] - 2025-10-02
### Changed
- **🎨 HDR highlight post-processing** - Direct smoothing of HDR regions for grain reduction
- **Selective Gaussian blur**: Only affects pixels with values > 1.0 (HDR highlights)
- **9×9 kernel with sigma=2.0**: Effective grain reduction without over-blurring
- **Smooth transition mask**: 15×15 Gaussian feathering prevents hard edges between smoothed/unsmoothed regions
- **Preserves displayable range**: 0-1 values remain untouched (sharp EV0 base preserved)
- **Fixes**: Directly smooths the final HDR values that appear grainy when exposed down in Nuke
### Technical Details
- Post-processing applied after detail injection (more effective than pre-filtering sources)
- Mask-based selective blending prevents affecting non-HDR regions
- Addresses grain created during injection process, not just source noise
## [1.1.5] - 2025-10-02
### Added
- **🎨 Bilateral filtering for grain reduction** - Smoother highlight details in Nuke/Resolve
- **Highlights (EV-2)**: 5x5 bilateral filter (sigmaColor=0.1, sigmaSpace=5)
- **Extreme highlights (EV-4)**: 7x7 bilateral filter (sigmaColor=0.15, sigmaSpace=7) - stronger smoothing
- **Shadows (EV+2/EV+4)**: 3x3 bilateral filter (sigmaColor=0.05, sigmaSpace=3) - light smoothing
- **Edge-preserving smoothing**: Reduces AI-generated grain without losing important detail
- **Fixes**: Highlights no longer appear grainy/sharp when exposed down in Nuke
### Technical Details
- Bilateral filtering applied to detail sources before injection
- Preserves edges and important detail while removing noise
- Stronger filtering for more underexposed images (more grain)
- Maintains HDR range and color accuracy
## [1.1.4] - 2025-10-02
### Fixed
- **🔆 Improved brightness compensation algorithm** - Better histogram distribution
- **Now uses median-based scaling** for very dark images (median < 0.05)
- **Uses mean-based scaling** for normal brightness images
- **More permissive adjustment range**: 0.3x to 8.0x (was 0.5x to 4.0x)
- **Better handling of shadow-heavy images** - prevents histogram crush to left
- **Fixes**: Histogram no longer compressed to shadows, better tonal distribution
## [1.1.3] - 2025-10-02
### Changed
- **🎨 Detail Injection is now the DEFAULT algorithm** - Best results for AI-generated images
- **Simplified output: Linear HDR only** - Removed sRGB display option
- Always outputs true linear HDR (perfect for EXR export)
- Linear data is correct format for professional color grading
- Preview may look contrasty in ComfyUI (this is expected and correct)
- **Algorithm order updated**: detail_injection listed first in dropdown menu
### Removed
- **Removed `output_colorspace` parameter** - Streamlined interface, always linear HDR output
## [1.1.2] - 2025-10-02
### Added
- **🎨 Output Colorspace Selection** - New parameter for all HDR processors
- **`srgb_display` (NEW DEFAULT)**: Tone-mapped output with Reinhard operator for natural preview in ComfyUI
- **`linear_hdr`**: True linear HDR output for EXR export (may look contrasty in preview)
- **Applies to all algorithms** - Consistent colorspace handling across radiance_fusion, detail_injection, etc.
- **Smart tone mapping**: Reinhard operator compresses HDR values >1.0 into displayable range
- **Preserves workflow flexibility**: Use sRGB for preview, linear for final EXR export
### Changed
- **Default output is now `srgb_display`** - Better out-of-box experience for ComfyUI users
- **Linear output properly documented** - Clear warnings that linear HDR looks contrasty in preview
## [1.1.1] - 2025-10-02
### Fixed
- **🚨 CRITICAL: Fixed inverted exposure adjustment formula** - Exposure adjustment was backwards!
- **Bug**: `+1.0` stop was darkening (0.5x) instead of brightening (2.0x)
- **Fix**: Removed negative sign from formula: `2^exposure_adjust` (was `2^(-exposure_adjust)`)
- **Impact**: All exposure adjustments now work correctly (positive = brighter, negative = darker)
- **🔆 Fixed Detail Injection producing dark images** - Added automatic brightness compensation
- **Issue**: Output had mean 0.13 instead of target 0.18 (18% middle gray standard)
- **Solution**: Automatic brightness scaling targets 0.18 mean for proper exposure
- **Uses percentile-based mean** (middle 80%) for robustness against outliers
- **Clamped to 0.5x-4.0x range** to prevent over-correction
- **Preserves HDR values proportionally** while normalizing overall brightness
## [1.1.0] - 2025-10-02
### Added
- **🎨 Detail Injection Algorithm** - Revolutionary AI-aware HDR processing for AI-generated exposure stacks
- **Automatic gamma analysis** - Detects sRGB gamma encoding (2.2) in AI-generated images
- **Proper sRGB to linear conversion** - Accurate color space transformation for HDR processing
- **Intelligent highlight detail injection**:
- Maps EV-2 (underexposed) detail into 1.0-2.0 HDR range for moderate highlights
- Maps EV-4 (very underexposed) detail into 2.0-4.0 HDR range for extreme highlights
- **Intelligent shadow detail injection**:
- Recovers shadow detail from EV+2 (overexposed) for moderate shadows
- Recovers deep shadow detail from EV+4 (very overexposed) for extreme shadows
- **Hermite interpolation** - Smooth S-curve blending prevents harsh transitions
- **Color preservation** - Maintains hue and color ratios using luminance-based scaling
- **EV0 as base** - Preserves natural appearance while extending dynamic range
- **Perfect for AI workflows** - Handles non-photometric AI-generated exposure stacks
- **Comprehensive logging** - Detailed step-by-step processing information
- **Supports both 3-stop and 5-stop processing** - Works with any exposure stack size
### Added
- **🆕 Latent Stack Processor (5 Stops)** - New node for averaging latent representations from 5 different exposures
- **👑 Ultimate Quality-Aware Blending (NEW DEFAULT!)** - Merges Laplacian pyramid + enhanced quality metrics!
- **Combines the best of both technologies** - multi-scale decomposition + sophisticated quality analysis
- **4-level Laplacian pyramid decomposition** - separates frequency bands for optimal blending
- **Adaptive quality power per frequency level**:
- Level 0 (finest details): Power = 3.8x (very selective for edges like tree leaves)
- Level 1 (fine details): Power = 2.8x (highly selective)
- Level 2 (medium details): Power = 2.1x (selective)
- Level 3+ (coarse/smooth): Power = 1.7x (balanced for smooth areas)
- **Enhanced quality metrics with edge emphasis**:
- Contrast: 60% weight (edges/details prioritized)
- Saturation: 25% weight (color richness)
- Exposedness: 15% weight (well-exposed regions)
- **Completely eliminates ALL ghosting artifacts** - tree leaves perfectly sharp!
- **Seamless smooth area blending** - sky remains perfectly smooth
- **Professional production-ready results** matching top HDR software!
- **⭐ Variance-Adaptive Blending** - Alternative approach with spatial smoothing
- Analyzes local variance across latents to detect problem areas
- 7x7 spatial smoothing prevents checkerboard patterns
- Adaptive per-pixel weighting based on variance analysis
- **🎯 Six Professional Blend Modes** - Complete arsenal of blending strategies:
- `quality_aware`: Multi-scale pyramid + enhanced quality (NEW DEFAULT!) 👑
- `variance_adaptive`: Spatial smoothing with variance analysis
- `weighted_center`: Simple center-biased weighting
- `strong_center`: Maximum noise reduction approach
- `median_blend`: Outlier rejection for robustness
- `simple_average`: Equal weights for maximum range
- **Detail Preservation Control** - New parameter (0.0-1.0) controls quality distinction sharpness (quality_aware) or artifact reduction strength (variance_adaptive)
- **Center Bias Control** - Adjustable weighting (0.0-0.8) to balance noise vs dynamic range
- **Fast latent processing** - Works with latent space instead of image space
- **Direct latent manipulation** - Processes before VAE decode for efficiency
- **NEW: Natural Blend Algorithm** - Now default! Preserves exact EV0 appearance with enhanced dynamic range
- **Smart luminance masking** - Seamless highlight and shadow detail recovery
+413 -58
View File
@@ -1,32 +1,50 @@
# Luminance Stack Processor - ComfyUI Custom Nodes
[![Version](https://img.shields.io/badge/version-1.0.5-blue.svg)](https://github.com/sumitchatterjee13/Luminance-Stack-Processor)
[![Version](https://img.shields.io/badge/version-1.1.8-blue.svg)](https://github.com/sumitchatterjee13/Luminance-Stack-Processor)
[![Python](https://img.shields.io/badge/python-3.11+-blue.svg)](https://python.org)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/sumitchatterjee13/Luminance-Stack-Processor/blob/main/LICENSE)
[![ComfyUI](https://img.shields.io/badge/ComfyUI-compatible-orange.svg)](https://github.com/comfyanonymous/ComfyUI)
[![GitHub](https://img.shields.io/badge/GitHub-Repository-black.svg)](https://github.com/sumitchatterjee13/Luminance-Stack-Processor)
Professional HDR (High Dynamic Range) processing nodes for ComfyUI featuring our **Radiance Fusion Algorithm** - a custom HDR processing method that delivers enhanced results through Nuke-inspired mathematical operations.
HDR (High Dynamic Range) processing nodes for ComfyUI featuring **Detail Injection** algorithm (default) and **Radiance Fusion Algorithm** - custom HDR processing methods that work well for both AI-generated and real-world images.
**Version: 1.0.5** | **Release Date: 2025-01-21**
**Version: 1.1.8** | **Release Date: 2025-10-02**
## 🎯 Features
- **🚀 RADIANCE FUSION ALGORITHM**: Our custom HDR algorithm developed in-house
- **Nuke-Inspired Mathematics**: Based on professional VFX pipeline operations (plus/average)
- **Enhanced HDR Preservation**: Maintains excellent dynamic range with natural appearance
- **Improved Results**: Provides quality improvements over traditional methods
- **Professional VFX Quality**: Suitable for film, TV, and visual effects work
- **🎨 DETAIL INJECTION ALGORITHM** *(DEFAULT since v1.1.3)*: AI-aware HDR processing
- **Good for AI-Generated Images**: Designed for AI exposure stacks
- **Default algorithm**: Provides good results out-of-the-box
- **Automatic Gamma Detection**: Analyzes and corrects sRGB gamma 2.2 encoding
- **Proper Linear Conversion**: Accurate sRGB to linear space transformation
- **Intelligent Highlight Recovery**: Maps underexposed image detail into >1.0 HDR range
- **Smart Shadow Recovery**: Injects overexposed detail into dark shadow regions
- **Automatic Brightness Compensation**: Targets professional 18% gray standard
- **Color Preservation**: Maintains hue using luminance-based scaling
- **Hermite Interpolation**: Smooth blending prevents harsh transitions
- **EV0 Base Preservation**: Keeps natural appearance while extending dynamic range
- **Linear HDR Output**: True HDR values for professional EXR export
- **🚀 RADIANCE FUSION ALGORITHM**: Custom HDR algorithm
- **Nuke-Inspired Mathematics**: Based on VFX pipeline operations (plus/average)
- **HDR Preservation**: Maintains good dynamic range with natural appearance
- **Alternative Results**: Provides different approach compared to traditional methods
- **For VFX Work**: Suitable for compositing workflows
- **🆕 TRUE 32-bit EXR Export**: Professional bit-depth control with imageio integration
- **🚨 TRUE HDR Values Above 1.0**: Proper HDR data preservation without normalization
- **🔬 DEBEVEC WITH ADAPTIVE CALIBRATION** *(Experimental)*:
- **AI-Aware Calibration**: Analyzes and corrects exposure relationships for AI-generated images
- **Physically-Based Recovery**: True linear radiance output
- **Anti-Banding Filtering**: Subtle bilateral filtering reduces quantization artifacts
- **Exposure Compensation**: Built-in -8 stop default for proper viewing in Nuke/Resolve
- **For VFX Work**: Scene-referred linear data for compositing workflows
- **Legacy HDR Algorithms** *(Work in Progress)*:
- **Robertson**: Alternative HDR method with adaptive calibration *(experimental)*
- **Natural Blend**: EV0 appearance preservation *(under refinement)*
- **Mertens**: Exposure fusion method *(being optimized)*
- **Debevec**: Traditional HDR recovery *(legacy support)*
- **Robertson**: Alternative HDR method *(legacy support)*
- **Three Custom Nodes**:
- **3-Stop Processor**: Merges EV+2, EV+0, EV-2 exposures
- **5-Stop Processor**: Merges EV+4, EV+2, EV+0, EV-2, EV-4 exposures
- **Four Custom Nodes**:
- **3-Stop Processor**: Merges EV+2, EV+0, EV-2 exposures (Image space)
- **5-Stop Processor**: Merges EV+4, EV+2, EV+0, EV-2, EV-4 exposures (Image space)
- **🆕 Latent Stack Processor**: Fast latent-space averaging for 5 exposures (Latent space)
- **HDR Export**: Saves EXR files with preserved HDR data
- **ComfyUI-Style Interface**: Filename and path inputs like built-in save nodes
- **HDR Verification**: Automatic checking that HDR data is preserved in exports
@@ -35,7 +53,7 @@ Professional HDR (High Dynamic Range) processing nodes for ComfyUI featuring our
### HDR Processing Comparison
See the dramatic difference our Radiance Fusion Algorithm makes in preserving detail across exposure ranges:
See the difference the Radiance Fusion Algorithm makes in preserving detail across exposure ranges:
#### Indoor Lighting Comparison
![Bulb Comparison](images/Bulb.jpg)
@@ -49,7 +67,204 @@ See the dramatic difference our Radiance Fusion Algorithm makes in preserving de
![Highlight Clamping Comparison](images/Reduce%20highlight%20clamping.jpg)
*Demonstration of reduced highlight clamping - preserving bright details that would normally be lost*
These comparison strips demonstrate how our HDR processing maintains detail in both highlights and shadows that would be lost in single-exposure captures.
These comparison strips demonstrate how my HDR processing maintains detail in both highlights and shadows that would be lost in single-exposure captures.
## 📖 Algorithm Explanation
### 🎨 Detail Injection Algorithm (Default)
**What makes Detail Injection different?**
Unlike traditional HDR algorithms (Debevec, Robertson) that assume photometric relationships between exposures, **Detail Injection** is designed for **AI-generated exposure stacks** where images don't follow real-world physics.
#### **The Problem It Solves:**
AI-generated images simulate different exposures but don't have true photometric relationships:
- Traditional HDR: `radiance_ev-2 = radiance_ev0 × 4` (physics-based)
- AI-generated: Each exposure is **independently created** (no physics relationship)
#### **How Detail Injection Works:**
**Step 1: sRGB to Linear Conversion**
- Detects sRGB gamma 2.2 encoding in AI images
- Converts to linear light space using proper sRGB curve
- Essential for physically accurate HDR calculations
**Step 2: Highlight Detail Injection** ✨
- **Problem**: EV0 highlights are clipped (pure white = 1.0)
- **Solution**: Use detail from underexposed images (EV-2, EV-4)
- **EV-2 detail → 1.0-2.0 HDR range** (moderate highlights)
- **EV-4 detail → 2.0-4.0 HDR range** (extreme highlights)
- Result: Bright areas have **recoverable detail** when you expose down in Nuke/Resolve
**Step 3: Shadow Detail Injection** 🌑
- **Problem**: EV0 shadows are crushed (pure black = 0.0)
- **Solution**: Use detail from overexposed images (EV+2, EV+4)
- **EV+2 detail → shadow recovery** (moderate shadows)
- **EV+4 detail → deep shadow recovery** (extreme shadows)
- Result: Dark areas have **liftable detail** when you brighten in post
**Step 4: Automatic Brightness Compensation** 🎚️
- Analyzes median/mean values
- Targets **0.18 (18% gray)** - professional standard
- Helps with proper exposure without manual adjustment
- Uses 0.3x-8.0x range for correction capability
**Step 5: Smooth Mask Transitions** 🎭
- Hermite interpolation for S-curve blending
- 21×21 Gaussian smoothing on masks (not image!)
- Gradual feathering over wide tonal ranges
- Helps reduce visible blend boundaries
#### **Why Use Detail Injection?**
✅ **For AI-Generated HDR Stacks**: Works with Flux, SD, MJ exposure variations
✅ **Natural EV0 Base**: Looks correct at middle exposure
✅ **True HDR Range**: Values >1.0 for color grading workflows
✅ **Automatic Exposure**: Helps with brightness adjustment
✅ **Smooth Blending**: Reduces harsh transitions and artifacts
✅ **Color Accuracy**: Maintains hue using luminance-based scaling
#### **When to Use Other Algorithms?**
- **Debevec with Adaptive Calibration**: For VFX compositing with scene-referred linear data (AI or real exposures)
- **Radiance Fusion**: When you want Nuke-style plus/average operations with display-ready output
- **Robertson with Adaptive Calibration**: Alternative to Debevec for VFX work
- **Mertens**: For quick preview/display-ready fusion without HDR math
- **Natural Blend**: When you want to preserve exact EV0 appearance
---
### 🔬 Debevec with Adaptive Calibration (NEW!)
**Adaptive approach to HDR recovery for AI-generated images!**
Traditional Debevec algorithm assumes **photometric consistency** - that brightness relationships follow physics:
```
EV+2 image = 4x brighter than EV0
EV-2 image = 4x darker than EV0
```
But **AI-generated images don't follow these rules!** Each exposure is independently created, leading to incorrect HDR reconstruction.
#### **My Solution: Adaptive Exposure Calibration**
I've developed a calibration system that **analyzes and corrects** the exposure relationships:
**Step 1: Analyze Actual Brightness Relationships**
```python
# For each AI-generated bracket:
1. Work in sRGB space (matching Debevec's input - NO linear conversion)
2. Compare actual brightness vs EV0 reference
3. Compute brightness ratios in well-exposed regions (0.2-0.8 luminance)
4. Use median filtering to reject outliers
```
**Step 2: Compute Corrected Exposure Times**
```python
# Example: EV+4 image
Nominal time: 0.267s (16x longer than EV0 - what physics says)
sRGB ratio: 2.064x (AI made it 2.064x brighter in sRGB space)
Time ratio: 4.924x (apply ^1.8 power for AI gamma)
Calibrated: 0.082s (corrected time that matches AI's behavior)
# The calibration tells Debevec:
# "This bright image had a SHORTER exposure than expected"
# So Debevec correctly interprets the scene radiance
```
**Step 3: Apply Debevec with Corrected Times**
```python
# Debevec now works correctly because:
- Exposure times match actual brightness relationships
- Camera response function accurately recovered
- Linear radiance correctly reconstructed
- No inverted tonality or broken highlights!
```
**Step 4: Anti-Banding Filter (Optional)**
```python
# Subtle bilateral filtering:
- Reduces 8-bit quantization banding
- Preserves edges (edge-aware filter)
- Maintains HDR peaks (80%/20% blend)
- Smooth gradients without blur
```
**Step 5: Exposure Compensation**
```python
# Default -8 stops (1/256 scale)
- Brings output to proper viewing levels
- Maintains relative dynamic range
- Ready for Nuke/Resolve without manual adjustment
```
#### **Technical Details**
**Calibration Algorithm:**
- **Reference anchor**: EV0 defines absolute scale
- **sRGB-space analysis**: Works in sRGB space (matching Debevec's input)
- **AI-tuned gamma**: Applies ^1.8 power (gentler than theoretical ^2.2)
- **Robust statistics**: Median ratios in 0.2-0.8 luminance range
- **Preserves ratios**: Only corrects relative relationships, not overall scale
- **Logging**: Detailed calibration report in console
**Why It Works:**
- Debevec's algorithm has 2 steps: estimate camera response, recover radiance
- AI's "broken" exposure relationships = weird camera response curve
- By adjusting exposure times, this approach tells Debevec about this "weird camera"
- Debevec adapts and correctly recovers the scene's linear radiance!
**When to Use Debevec:**
- ✅ **VFX compositing in Nuke/After Effects** - Scene-referred linear data
- ✅ **Color grading workflows** - Maximum flexibility for post-processing
- ✅ **AI-generated brackets** - Adaptive calibration helps with non-physical exposures
- ✅ **Real camera exposures** - Works for traditional bracketing too
- ✅ **When you need physically-based radiance** - Linear radiance values
**Parameters:**
- `auto_calibrate`: Enable/disable adaptive calibration (default: True)
- `debevec_exposure_comp`: Exposure compensation in stops (default: -8.0)
- `debevec_anti_banding`: Enable subtle filtering (default: True)
**Example Log Output:**
```
============================================================
ADAPTIVE EXPOSURE CALIBRATION (sRGB SPACE)
Analyzing AI-generated brackets as Debevec sees them
============================================================
Reference image (EV0): Index 2, Nominal time: 0.016667s
Working in sRGB space (matching Debevec's input)
Calibrating Image 0 (EV+4):
Valid pixels: 826228
sRGB brightness ratio: 2.064
Exposure time ratio (^1.8): 4.924
Expected time ratio: 16.000
Nominal time: 0.266667s → Calibrated time: 0.082071s
Adjustment factor: 0.308x
[... calibration for other images ...]
Debevec raw output: [0.010, 116377.52]
Applied anti-banding filter...
Applied exposure compensation: -8.0 stops (factor: 0.003906x)
Debevec compensated output: [0.00004, 454.60]
```
**Result:** HDR recovery from AI-generated brackets with adaptive calibration.
---
### 🚀 Radiance Fusion Algorithm
Nuke-inspired HDR blending using mathematical operations:
- **Plus operation**: Adds all outer exposures
- **Average operation**: Balances with center exposure
- **HDR preservation**: Maintains good dynamic range
- **Good for**: VFX workflows familiar with Nuke-style operations
---
## 📋 Requirements
@@ -98,26 +313,26 @@ These comparison strips demonstrate how our HDR processing maintains detail in b
## 📁 ComfyUI Workflow
A complete example workflow for ComfyUI is provided in the `/workflow` directory. This demonstrates a good setup for HDR processing using our Radiance Fusion algorithm.
A complete example workflow for ComfyUI is provided in the `/workflow` directory. This demonstrates a good setup for HDR processing using my Radiance Fusion algorithm.
### Example Workflow Setup
![ComfyUI Workflow](images/Comfyui%20workflow.jpg)
*Complete ComfyUI workflow showing proper HDR processing setup with our custom nodes*
*Complete ComfyUI workflow showing proper HDR processing setup with my custom nodes*
## 🎨 AI-Generated HDR from Single Images
We've developed a complete workflow for creating HDR images from a single source image using **FLUX.1 Kontext exposure control LoRAs**:
I've developed a complete workflow for creating HDR images from a single source image using **FLUX.1 Kontext exposure control LoRAs**:
### 🚀 **The Complete Pipeline:**
1. **Start with any image** - Generated from any model or captured photo
2. **Generate exposure variants** - Use our trained LoRAs to create EV-4, EV-2, EV0, EV+2, EV+4 versions
3. **Process with Radiance Fusion** - Feed the synthetic exposures into our HDR nodes
2. **Generate exposure variants** - Use my trained LoRAs to create EV-4, EV-2, EV0, EV+2, EV+4 versions
3. **Process with Radiance Fusion** - Feed the synthetic exposures into my HDR nodes
4. **Get professional HDR** - Output true 32-bit HDR images with enhanced dynamic range
### 📦 **Exposure Control LoRAs:**
Our custom-trained LoRAs for **FLUX.1 Kontext (dev)** can generate different exposure levels from a single image:
My custom-trained LoRAs for **FLUX.1 Kontext (dev)** can generate different exposure levels from a single image:
- **Available LoRAs**: `ev-4`, `ev-2`, `ev+2`, `ev+4` (with corresponding trigger words)
- **Easy to use**: Simply add the trigger word and adjust LoRA weight
@@ -128,7 +343,7 @@ Our custom-trained LoRAs for **FLUX.1 Kontext (dev)** can generate different exp
- ✅ **Single image input** - No need for multiple captures or bracketing
- ✅ **AI-generated exposures** - Perfect synthetic exposure variants
- ✅ **Professional HDR output** - True HDR with our Radiance Fusion processing
- ✅ **Professional HDR output** - True HDR with my Radiance Fusion processing
- ✅ **Complete automation** - Generate and process in one workflow
- ✅ **Creative freedom** - Work with any generated or captured image
@@ -162,7 +377,7 @@ Perfect for standard HDR bracketing with 3 exposures:
- `ev_minus_2`: Underexposed image (-2 EV)
- `exposure_step`: (Optional) EV step size (default: 2.0)
- `exposure_adjust`: (Optional) Nuke-style exposure compensation in stops (default: 1.0)
- `hdr_algorithm`: Choose **"radiance_fusion"** (default - *our custom algorithm*), "natural_blend", "mertens", "debevec", "robertson"
- `hdr_algorithm`: Choose **"radiance_fusion"** (default - *my custom algorithm*), "natural_blend", "mertens", "debevec", "robertson"
**Output:**
- `hdr_image`: HDR tensor with values potentially above 1.0
@@ -191,17 +406,118 @@ For extended dynamic range with 5 exposures:
- `ev_minus_4`: Underexposed image (-4 EV)
- `exposure_step`: (Optional) EV step size (default: 2.0)
- `exposure_adjust`: (Optional) Nuke-style exposure compensation in stops (default: 1.0)
- `hdr_algorithm`: Choose **"radiance_fusion"** (default - *our custom algorithm*), "natural_blend", "mertens", "debevec", "robertson"
- `hdr_algorithm`: Choose **"radiance_fusion"** (default - *my custom algorithm*), "natural_blend", "mertens", "debevec", "robertson"
**Output:**
- `hdr_image`: HDR tensor with values potentially above 1.0
### 🆕 Latent Stack Processor (5 Stops)
**NEW!** Fast latent-space processing with **noise reduction**:
**What it does:**
- Performs weighted averaging of latent representations with multiple blend modes
- Works directly in latent space (before VAE decode)
- Faster than image-space processing
- **Built-in noise reduction** through smart blending strategies
- Ideal for diffusion model workflows
**Inputs:**
- `latent_1`: First exposure latent (e.g., EV+4)
- `latent_2`: Second exposure latent (e.g., EV+2)
- `latent_3`: Third exposure latent (e.g., EV0 - center exposure)
- `latent_4`: Fourth exposure latent (e.g., EV-2)
- `latent_5`: Fifth exposure latent (e.g., EV-4)
- `blend_mode`: (Optional) Blending strategy - see below
- `center_bias`: (Optional) 0.0-0.8, how much to favor center exposure (default: 0.4)
**Output:**
- `merged_latent`: Intelligently blended latent that can be decoded with VAE
**🎯 Blend Modes (Noise & Artifact Reduction Strategies):**
1. **`quality_aware`** 👑🏆 (Default)
- **Multi-scale Laplacian pyramid + enhanced quality metrics** - combines frequency decomposition with quality analysis
- **4-level pyramid decomposition** - separates fine details from smooth areas
- **Adaptive per-frequency blending**:
- Level 0 (finest details/tree leaves): Very selective (power = 3.8x with default settings)
- Level 1 (fine details): Highly selective (power = 2.8x)
- Level 2 (medium details): Selective (power = 2.1x)
- Level 3+ (coarse/smooth areas): Balanced (power = 1.7x)
- **Enhanced quality metrics with edge emphasis**:
- Contrast: 60% weight (edges/details prioritized)
- Saturation: 25% weight (color richness)
- Exposedness: 15% weight (well-exposed regions)
- **Result:** Tree leaves sharp, sky smooth, reduced artifacts!
- **Use when:** You want good results with reduced artifacts (DEFAULT!) 👑
- **Parameters:**
- `detail_preservation` (0.0-1.0, default 0.7): Controls selectivity sharpness
- `center_bias` (0.0-0.8, default 0.4): Boosts center exposure baseline quality
2. **`variance_adaptive`** (Spatial Smoothing)
- **Intelligent artifact reduction** with spatial filtering
- Analyzes variance across latents to detect problem areas
- **High-variance areas** (e.g., inconsistent details): Favors center exposure
- **Low-variance areas** (e.g., smooth regions): Uses full dynamic range blending
- Adaptive weights with 7x7 spatial smoothing to prevent checkerboard
- **Use when:** Alternative approach, good for specific cases
3. **`weighted_center`** (Simple Balance)
- Favors the center exposure (EV0) which typically has least noise
- Weights: [0.075, 0.1, 0.7, 0.1, 0.075] with default `center_bias=0.4`
- **Good balance** of dynamic range and noise reduction
- **Use when:** You want simpler processing without adaptive analysis
4. **`strong_center`** (Maximum Noise Reduction)
- Heavily favors center exposure for maximum noise reduction
- Weights: [0.025, 0.075, 0.8, 0.075, 0.025] with default `center_bias=0.4`
- Cleanest output but less dynamic range expansion
- **Use when:** Noise is more problematic than dynamic range
5. **`median_blend`** (Outlier Rejection)
- Excludes outliers (min/max values) per pixel
- Averages middle 3 values: `(sorted[1] + sorted[2] + sorted[3]) / 3`
- Excellent noise reduction while preserving detail
- **Use when:** You have very noisy latents or want robust averaging
6. **`simple_average`** (Maximum Dynamic Range)
- Equal weights: `(L1 + L2 + L3 + L4 + L5) / 5`
- Maximum dynamic range but most noise and artifacts
- **Use when:** Input latents are already clean
**💡 Artifact & Noise Reduction Tips:**
- **Use `quality_aware`** (DEFAULT) 👑 - multi-scale solution with enhanced quality metrics
- **For tree leaf ghosting**: Multi-scale pyramid helps reduce this - finest details use highest power selectivity
- **Default settings work well** - adaptive quality power per frequency handles most cases
- **Optional tuning:**
- Increase `detail_preservation` (0.8-0.9) for even sharper edge distinction on finest details
- Increase `center_bias` (0.5-0.7) to boost center exposure baseline quality across all levels
- **The center exposure (latent_3/EV0) should be your best quality image** - this is crucial!
**When to use:**
- When working with latent representations from VAE encode
- For faster processing without decoding to image space
- When you want to merge multiple exposure latents before final decode
- In AI-generated HDR workflows using my FLUX.1 Kontext LoRAs
- When you need noise reduction in latent space
**Workflow Example:**
1. Encode 5 exposure images to latents using VAE Encode
2. Connect all 5 latents to Latent Stack Processor
3. Use default `quality_aware` mode (ultimate solution!) 👑
4. Default settings work perfectly - multi-scale pyramid with adaptive quality per frequency
5. Optional fine-tuning (rarely needed):
- Increase `detail_preservation` (0.8-0.9) for even sharper edge selectivity
- Increase `center_bias` (0.5-0.7) to boost center exposure across all pyramid levels
6. Decode the merged latent with VAE Decode
7. Enjoy **good results** - tree leaves sharp, sky smooth, reduced artifacts!
### 📋 **Complete HDR Workflow Example:**
1. **Load Images**: Load your bracketed exposures (3 or 5 images)
2. **Add Processing Node**: "Luminance Stack Processor (3/5 Stops)"
3. **Connect Exposures**: Connect each EV image to corresponding input
4. **Choose Algorithm**: Select HDR algorithm (**Radiance Fusion recommended - our custom algorithm**)
4. **Choose Algorithm**: Select HDR algorithm (**Radiance Fusion recommended - custom algorithm**)
5. **Add Export Node**: "HDR Export to EXR"
6. **Connect HDR Output**: From processor to export node
7. **Set Filename**: Enter desired filename prefix
@@ -210,23 +526,45 @@ For extended dynamic range with 5 exposures:
## 🔬 How It Works
The nodes feature our **Radiance Fusion Algorithm** as the default, plus traditional algorithms for compatibility:
The nodes feature the **Radiance Fusion Algorithm** as the default, plus traditional algorithms for compatibility:
1. **Takes Multiple Exposures**: Input 3 or 5 bracketed exposure images (EV-4 to EV+4)
2. **Selects HDR Algorithm**: Choose **Radiance Fusion** (our custom algorithm) or traditional methods
2. **Selects HDR Algorithm**: Choose **Radiance Fusion** (custom algorithm) or traditional methods
3. **Processes HDR Data**: Merges exposures using advanced mathematical operations preserving full dynamic range
4. **Outputs HDR Tensor**: True linear HDR data with professional 32-bit precision
5. **🚨 CRITICAL: Use HDR Export Node**: Exports professional 32-bit EXR files with preserved HDR values
### 🎯 **HDR Algorithm Options:**
#### **🚀 Radiance Fusion (Default - Our Custom Algorithm)**
#### **🚀 Radiance Fusion (Default - Custom Algorithm)**
- **📈 HDR Range**: Wide dynamic range with good preservation
- **🧮 Advanced Mathematics**: Nuke-inspired plus/average operations for enhanced results
- **🎬 Professional Quality**: VFX-grade HDR processing with natural appearance
- **⚡ Good Performance**: Well-balanced dynamic range and visual appeal
- **🔬 In-House Development**: Our custom algorithm with improvements over traditional methods
- **💎 Quality Focus**: Enhanced compared to standard HDR techniques
- **🧮 Mathematics**: Nuke-inspired plus/average operations
- **🎬 Quality**: VFX-oriented HDR processing with natural appearance
- **⚡ Performance**: Well-balanced dynamic range and visual appeal
- **🔬 Custom Development**: Custom algorithm with improvements over traditional methods
- **💎 Quality Focus**: Enhanced compared to standard techniques
---
#### **🔬 Debevec with Adaptive Calibration** *(Experimental)*
- **Status**: Functional with AI-aware calibration
- **HDR Range**: Raw linear radiance (0 to 8000+ values)
- **Purpose**: Scene-referred linear radiance for VFX workflows
- **Best For**:
- VFX compositing in Nuke/After Effects
- Color grading workflows
- AI-generated exposure brackets (adaptive calibration)
- Real camera exposures (traditional bracketing)
- **Features**:
- Automatic exposure time calibration for AI images
- Anti-banding bilateral filtering
- Built-in exposure compensation (-8 stops default)
- Detailed calibration logging
#### **⚙️ Robertson with Adaptive Calibration** *(Experimental)*
- **Status**: Alternative to Debevec with same calibration
- **HDR Range**: Raw linear radiance
- **Purpose**: Alternative HDR recovery method with calibration
---
@@ -242,16 +580,6 @@ The nodes feature our **Radiance Fusion Algorithm** as the default, plus traditi
- **HDR Range**: 1-12 (medium HDR values)
- **Purpose**: Traditional exposure fusion method
#### **Debevec Algorithm** *(Legacy Support)*
- **Status**: Maintained for compatibility
- **HDR Range**: Raw linear radiance (VFX standard)
- **Purpose**: Traditional HDR recovery (1997 method)
#### **Robertson Algorithm** *(Legacy Support)*
- **Status**: Maintained for compatibility
- **HDR Range**: Raw linear radiance (VFX standard)
- **Purpose**: Alternative traditional HDR method
## 📸 Best Practices
### For Capturing Source Images (Traditional Method):
@@ -263,7 +591,7 @@ The nodes feature our **Radiance Fusion Algorithm** as the default, plus traditi
### For AI-Generated Exposures (Modern Workflow):
- Start with **any single image** (generated or captured)
- Use our **FLUX.1 Kontext LoRAs** to create exposure variants
- Use my **FLUX.1 Kontext LoRAs** to create exposure variants
- Download LoRAs: [Flux-Kontext-exposure-control-LoRAs](https://huggingface.co/Sumitc13/Flux-Kontext-exposure-control-LoRAs)
- Generate **ev-4, ev-2, ev+2, ev+4** variants using trigger words
- **Perfect alignment** - AI ensures consistent composition
@@ -276,7 +604,7 @@ The nodes feature our **Radiance Fusion Algorithm** as the default, plus traditi
- **5-Stop**: +4, +2, 0, -2, -4 EV (16x range)
- Adjust `exposure_step` parameter if using different increments
#### AI-Generated (Using Our LoRAs):
#### AI-Generated (Using My LoRAs):
- **Base image**: Your source image (acts as EV 0)
- **Generate variants**: Use `ev-4`, `ev-2`, `ev+2`, `ev+4` LoRAs with trigger words
- **Perfect range**: Covers full 8-stop dynamic range
@@ -284,24 +612,51 @@ The nodes feature our **Radiance Fusion Algorithm** as the default, plus traditi
### Algorithm Selection Guide:
#### 🎬 **For VFX/Post-Production:**
- **🚀 Radiance Fusion** (Recommended): Our custom algorithm - good for professional work
- **🔬 Debevec** *(Legacy)*: Traditional raw radiance method
- **⚙️ Robertson** *(Legacy)*: Alternative traditional method
#### 🎬 **For VFX/Post-Production (Scene-Referred Linear):**
- **🔬 Debevec with Adaptive Calibration** *(Experimental)*: AI-aware calibration for non-physical exposures
- For Nuke/After Effects compositing workflows
- Works with both AI-generated and real camera exposures
- Includes anti-banding and exposure compensation
- Outputs true linear radiance (flat/desaturated is correct!)
- **⚙️ Robertson with Adaptive Calibration** *(Experimental)*: Alternative to Debevec with same features
- **🚀 Radiance Fusion**: Nuke-style operations with more display-friendly output
#### 🎨 **For Photography/Display:**
- **🚀 Radiance Fusion** (Recommended): Our custom algorithm - enhanced quality
#### 🎨 **For Photography/Display (Display-Referred):**
- **🎨 Detail Injection** (Default): Good for AI-generated images with natural appearance
- Automatic brightness compensation
- Display-ready output
- True HDR values with smooth blending
- **🚀 Radiance Fusion**: Good quality with decent dynamic range
- **🌟 Natural Blend** *(Work in Progress)*: Being optimized for better results
- **💫 Mertens** *(Work in Progress)*: Traditional method under improvement
#### 💡 **Important:**
- **VFX Algorithms** (Debevec/Robertson): Flat, desaturated appearance - **this is professional standard!**
- **Display Algorithms** (Natural Blend/Mertens): Enhanced, natural-looking, ready for viewing
- Raw linear radiance for compositing and grading
- Apply viewing LUTs in Nuke/Resolve for proper display
- **Display Algorithms** (Detail Injection/Radiance Fusion): Enhanced, natural-looking, ready for viewing
- Automatic tone mapping and exposure compensation
- Great for final output or quick previews
## ⚙️ Technical Details
- **Primary Algorithm**: **Radiance Fusion** - Our custom HDR processing method
- **Legacy Algorithms**: Natural Blend, Mertens, Debevec, Robertson *(work in progress)*
- **Production Algorithms**:
- **Detail Injection** (Default): AI-aware HDR with automatic brightness compensation
- **Radiance Fusion**: Custom Nuke-style HDR algorithm
- **Debevec with Adaptive Calibration**: VFX-grade scene-referred linear radiance
- **Robertson with Adaptive Calibration**: Alternative VFX HDR recovery
- **Adaptive Calibration System**:
- Automatic analysis of AI-generated exposure relationships
- sRGB-space analysis (matching Debevec's input)
- AI-tuned gamma correction (^1.8 power for AI images)
- Robust brightness ratio computation using median filtering
- EV0-anchored exposure time correction
- Detailed calibration logging for transparency
- **Anti-Banding Technology**:
- Edge-aware bilateral filtering (5x5 kernel)
- Preserves HDR peaks (80%/20% blend)
- Reduces 8-bit quantization artifacts
- **Legacy Algorithms**: Natural Blend, Mertens *(work in progress)*
- **Input Format**: 8-bit ComfyUI IMAGE tensors (standard ComfyUI format)
- **Output Format**: True 32-bit linear HDR with unlimited dynamic range
- **Processing**: Advanced mathematical operations + OpenCV integration
@@ -329,7 +684,7 @@ The nodes feature our **Radiance Fusion Algorithm** as the default, plus traditi
- Ensure input images are properly exposed (not all over/under)
- Check that images are aligned (use tripod)
- Verify EV differences match your capture method
- **Recommended**: Use Radiance Fusion (our custom algorithm) for good results
- **Recommended**: Use Radiance Fusion (my custom algorithm) for good results
- **Legacy algorithms**: Available for compatibility but under active improvement
5. **Memory issues**:
@@ -398,7 +753,7 @@ luminance-stack-processor/
- **Debevec, P. E., & Malik, J.** (1997). Recovering high dynamic range radiance maps from photographs. *ACM SIGGRAPH Computer Graphics*, 31(Annual Conference Series), 367-378.
- **OpenCV HDR Documentation**: https://docs.opencv.org/4.x/d3/db7/tutorial_hdr_imaging.html
- **ComfyUI Custom Node Guidelines**: https://docs.comfy.org/custom-nodes/
- **Our FLUX.1 Kontext Exposure LoRAs**: [Flux-Kontext-exposure-control-LoRAs](https://huggingface.co/Sumitc13/Flux-Kontext-exposure-control-LoRAs)
- **My FLUX.1 Kontext Exposure LoRAs**: [Flux-Kontext-exposure-control-LoRAs](https://huggingface.co/Sumitc13/Flux-Kontext-exposure-control-LoRAs)
- **Semantic Versioning**: https://semver.org/
## 📜 License
@@ -416,7 +771,7 @@ For issues, questions, or contributions:
- Ensure all dependencies are properly installed
### Contributing
We welcome contributions! Please:
I welcome contributions! Please:
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
@@ -425,4 +780,4 @@ We welcome contributions! Please:
---
**Happy HDR Processing with Radiance Fusion!** 🚀✨ | **Version 1.0.5** | **Featuring Our Custom Algorithm**
**Happy HDR Processing with Radiance Fusion!** 🚀✨ | **Version 1.1.8** | **Featuring Custom Algorithm**
+2 -1
View File
@@ -15,7 +15,7 @@ Installation:
3. Restart ComfyUI
Author: Sumit Chatterjee
Version: 1.0.5
Version: 1.1.8
License: MIT
"""
@@ -40,6 +40,7 @@ try:
from .luminance_stack_processor import (
LuminanceStackProcessor3Stops,
LuminanceStackProcessor5Stops,
LatentStackProcessor5Stops,
NODE_CLASS_MAPPINGS as NODES,
NODE_DISPLAY_NAME_MAPPINGS as DISPLAY_NAMES
)
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "luminance-stack-processor"
version = "1.0.5"
version = "1.1.8"
description = "Professional HDR processing nodes for ComfyUI using the Debevec Algorithm"
readme = "README.md"
license = { text = "MIT" }
@@ -72,13 +72,13 @@ include = ["luminance_stack_processor*"]
[tool.comfy]
name = "luminance-stack-processor"
description = "Professional HDR processing nodes for ComfyUI using the Debevec Algorithm"
version = "1.0.5"
version = "1.1.8"
author = "Sumit Chatterjee"
license = "MIT"
# Version management
[tool.bumpversion]
current_version = "1.0.5"
current_version = "1.1.8"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
+5 -5
View File
@@ -2,16 +2,16 @@
Version information for Luminance Stack Processor
"""
__version__ = "1.0.5"
__version_info__ = (1, 0, 5)
__version__ = "1.1.8"
__version_info__ = (1, 1, 8)
# Semantic versioning components
MAJOR = 1
MINOR = 0
PATCH = 5
MINOR = 1
PATCH = 8
# Build metadata
BUILD_DATE = "2025-01-20"
BUILD_DATE = "2025-10-02"
AUTHOR = "Sumit Chatterjee"
DESCRIPTION = "Professional HDR processing nodes using the Debevec Algorithm"