Add files via upload

This commit is contained in:
QL-boy
2026-01-17 19:16:29 +08:00
committed by GitHub
parent bb64b582b7
commit a6b2fe4d94
+137 -49
View File
@@ -1,14 +1,16 @@
# ComfyUI-Advanced-Tile-Processing
[中文](README_CN.md) [English](README.md)
**ComfyUI-Advanced-Tile-Processing** is an advanced custom node plugin suite designed specifically for ComfyUI. It aims to solve VRAM out-of-memory (OOM) bottlenecks in ultra-high-resolution image generation and processing by employing intelligent tiling and seamless merging techniques based on weighted accumulation, enabling stable processing of 4K, 8K, and even higher resolution images on standard consumer-grade graphics cards.
**ComfyUI-Advanced-Tile-Processing** is an advanced custom node plugin suite designed specifically for ComfyUI. It aims to solve VRAM out-of-memory (OOM) bottlenecks in ultra-high-resolution image generation and processing by employing intelligent tiling and multiple advanced fusion techniques for seamless merging, enabling stable processing of 4K, 8K, and even higher resolution images on standard consumer-grade graphics cards.
## 🌟 Core Features
- **Smart Dimension Awareness**: Automatically calculates optimal slicing coordinates. Supports "edge fallback" strategy to ensure complete coverage of the original image without introducing black borders (padding), thus avoiding artifacts generated by models.
- **Seamless Weighted Fusion**: Built-in multiple blending modes (Gaussian, Cosine, Linear). Through weighted averaging of overlapping regions across multiple layers, it maximizes the elimination of "grid seams" produced by physical stitching.
- **Multiple Advanced Fusion Techniques**: Supports linear blending, Gaussian blending, multi-band fusion (Laplacian Pyramid), and direct stitching.
- **Histogram Matching**: Based on the Reinhard algorithm, matches color distribution between adjacent tiles before fusion to eliminate color differences.
- **Optimal Seamline Computation**: Supports dynamic programming and centerline seam modes with search radius limitation, automatically finding the minimum energy path to avoid cutting important content.
- **Metadata-Driven Workflow**: The Splitter generates a unique `TILE_CONFIG` object containing original dimensions, scaling factors, and coordinates. The Merger automatically reads configurations for one-click restoration without manual parameter alignment.
- **Deep Compatibility**: Perfectly compatible with ComfyUI's list execution mechanism. Supports submitting tiles as `BATCH` for maximum inference speed or as `LIST` for loop node processing. When VRAM is insufficient, `LIST` is recommended over `BATCH`.
- **High-Performance Architecture**: Fully based on PyTorch tensor operations with GPU acceleration, ensuring performance remains optimal when handling large images.
- **Dynamic Size Support (Tiled Upscale)**: Supports dynamic size adjustment (Tiled Upscale), allowing upscaling after tiling. The Merger can automatically detect fragment size changes and dynamically adjust canvas size.
## 🛠 Installation Instructions
@@ -23,108 +25,194 @@ cd ComfyUI/custom_nodes/
3. Clone this repository:
```
git clone [https://github.com/QL-boy/ComfyUI-Advanced-Tile-Processing.git](https://github.com/QL-boy/ComfyUI-Advanced-Tile-Processing.git)
git clone https://github.com/QL-boy/ComfyUI-Advanced-Tile-Processing.git
```
4. Restart ComfyUI.
## 🧩 Node Details
### 1. 🔧 Advanced Tile Splitter (Splitter)
![](./nodes/tile_splitter.png)
Splits the input large image or latent space into overlapping smaller tiles.
- **Input Ports**:
- `image`: (optional) Original image.
- `latent`: (optional) Latent space data.
- **Core Parameters**:
- `tile_size`: Tile resolution (e.g., 512, 1024).
- `overlap`: Overlapping pixels between two tiles. Recommended to be 10% or more of `tile_size` for optimal blending.
- `rows`: Fixed number of rows (automatically calculated when set to 0).
- `columns`: Fixed number of columns (automatically calculated when set to 0).
- `normalize`: Whether to align dimensions to multiples of 64 (recommended for compatibility).
- **Output Ports**:
- `tile_config`: Core configuration file (must be connected to Merger), containing all metadata required for merging.
- `tiles_image_batch`: Merges all tiles into a Batch Tensor for high-performance sampling.
- `tiles_image_list`: (List mode) List of tile images, triggering ComfyUI loop execution.
- `tiles_latent_batch / list`: Corresponding outputs for latent space.
- `tile_config`: Core configuration file (must be connected to Merger), containing all metadata required for merging.
- `tiles_latent_batch`: Merged Latent Batch.
- `tiles_latent_list`: (List mode) List of tile Latents.
### 2. 🔧 Advanced Tile Merger (Merger)
![](./nodes/tile_merger.png)
Seamlessly reconstructs processed fragments based on tile configuration.
- **Input Ports**:
- `tile_config`: Configuration object output by Splitter.
- `processed_tiles_image`: (optional) Processed image fragments.
- `processed_tiles_latent`: (optional) Processed latent fragments.
- **Core Parameters**:
- `blend_mode`:
- `gaussian` (default): Higher weight at the center, smoothly decaying towards the edges, providing the most natural blending.
- `cosine`: Classic trigonometric decay, with a wider transition area.
- `linear`: Linear pyramid blending.
- `none`: Hard edge stitching (will have noticeable seams).
- `feather_percent`: Feathering percentage (0-50%), controlling the starting position of weight decay, with higher values resulting in wider edge blending areas.
- `blend_mode`: Fusion mode
- `linear`: Linear blending.
- `gaussian` (default): Gaussian weight blending, higher weight at the center with smooth decay towards edges, providing the most natural fusion.
- `multi_band`: Multi-band fusion (Laplacian Pyramid), highest quality fusion effect, suitable for high-contrast edges.
- `none`: Hard edge stitching (will have noticeable seams).
- `blend_strength`: Fusion strength, controlling feathering degree.
- `seam_mode`: Seamline mode
- `optimal`: Dynamic programming to compute the minimum energy path.
- `middle`: Directly use the centerline of the overlapping area.
- `histogram_matching`: Whether to enable histogram matching to eliminate color differences between adjacent tiles.
- `seam_search_radius`: Seamline search radius, limiting seamline fluctuations around the centerline.
- Internal Mechanism:
- **Output Ports**:
- `merged_image`: Merged complete image.
- `merged_latent`: Merged complete Latent.
- **Internal Mechanism**:
The node automatically unpacks `LIST` inputs. If your upstream is a loop node, ensure all tiles have been processed before feeding them into the Merger.
## 📖 Core Algorithm Principle: Weighted Fusion (Soft Blending / Accumulation Buffer Weighted Averaging)
## 📖 Core Algorithm Principles
To eliminate seams and brightness variations caused by traditional "cut-paste" methods, this plugin employs **Accumulation Buffer Weighted Averaging**, achieving smooth fusion of multiple pixels in overlapping regions. The core process is as follows:
### 1. Tiling Strategy
The splitter employs intelligent coordinate calculation to ensure:
- Complete coverage of the original image without gaps
- Even distribution of overlapping regions
- Support for fixed row/column numbers or automatic calculation
- Support for dimension alignment to multiples of 8 or 64
1. **Weight Mask Generation**
Generates a weight mask matrix $M$ for each image tile. In Gaussian mode, the center point has a weight of 1.0, decaying exponentially towards the edges, ensuring that the center region contributes the most during blending while the edges gradually transition.
2. **Pixel Accumulation and Weight Accumulation**
- **Pixel Accumulation**: Adds the weighted pixel values of the current tile to the corresponding position on the global canvas:
$Canvas += Tile \times M$
- **Weight Accumulation**: Simultaneously adds the mask values to the weight map:
$WeightMap += M$
3. **Normalization Output**
After all tiles have been accumulated, each pixel is normalized to obtain the final image:
$Pixel_{final} = \frac{Canvas}{WeightMap + \epsilon} = \frac{\sum (Tile_i \times M_i)}{\sum M_i + \epsilon}$
where $\epsilon$ is a small constant to prevent division by zero.
### Key Advantages
- **Seamless Transition**: Overlapping regions are contributed by multiple tiles based on weights, maintaining brightness and contrast consistency through normalization;
- **Artifact Resistance**: Smooth weight changes avoid hard edges, achieving a natural visual gradient;
- **Flexibility**: Can adapt to different tile overlap strategies by adjusting the weight decay curve.
### 2. Multi-Mode Fusion Techniques
This method essentially performs **soft blending** by averaging pixel values across multiple layers in overlapping regions, achieving high-quality, seamless large image synthesis.
## 🚀 Example Workflow
### SDXL Classic Tiling Sampling High-Resolution Repair and Reproduction
#### A. Linear Blending
Simple linear interpolation in overlapping regions, fast but may produce blurring at edges.
#### B. Gaussian Blending
Uses Gaussian kernel functions to generate weight masks, with high center weights smoothly decaying towards edges:
$$ M(x,y) = e^{-\frac{(x-x_c)^2+(y-y_c)^2}{2\sigma^2}} $$
#### C. Multi-band Blending
High-quality fusion based on Laplacian pyramid:
1. Build Gaussian and Laplacian pyramids of images
2. Fuse at each level separately
3. Reconstruct image from the top level
Advantages:
- Preserves high-frequency details
- Smoothly transitions low-frequency information
- Eliminates ghosting effects
#### D. Optimal Seamline
Compute minimum energy path through dynamic programming:
$$ E_{total} = E_{color} + \lambda \cdot E_{geometry} $$
Where:
- $E_{color}$ is color difference
- $E_{geometry}$ is geometric constraint (staying close to centerline)
- $\lambda$ is balancing parameter
### 3. Histogram Matching
Based on the Reinhard algorithm, matches statistical characteristics of source image to reference image:
$$ I_{matched} = \frac{(I - \mu_s)}{\sigma_s} \times \sigma_t + \mu_t $$
Where:
- $\mu_s, \sigma_s$ are mean and standard deviation of source image
- $\mu_t, \sigma_t$ are mean and standard deviation of target image
### 4. Latent Space Merging
For latent space, a simplified "center crop" strategy is used:
- Each tile takes the center part within overlapping regions
- Directly pastes onto canvas without blending
- 8x downsampling correspondence
## 🚀 Usage Recommendations
### Best Practice Configurations
| Scenario | Recommended Parameters |
|----------|------------------------|
| General image stitching | overlap=64, blend_mode="gaussian", blend_strength=0.25 |
| High contrast images | overlap=128, blend_mode="multi_band", blend_strength=0.3 |
| Significant color differences | Enable histogram_matching, seam_mode="optimal" |
| Speed priority | blend_mode="linear", seam_mode="middle" |
### Performance Optimization
1. **Batch Mode**: When tile count is low (≤4) and VRAM is sufficient, use Batch mode for highest performance
2. **List Mode**: When tile count is high or VRAM is limited, use List mode for sequential processing
3. **Search Radius**: Set appropriate seam_search_radius (e.g., 10-20) to accelerate optimal seam computation
### Common Workflows
### SDXL 经典分块采样高清修复复刻
![](<./example_workflows/SDXL 经典分块采样高清修复复刻.png>)
### Z-Image Quality Upgrade
### Z-Image质量升级
![](./example_workflows/Z-Image质量升级.png)
###
## ⚠️ Common Issues (FAQ)
- **Q: Why are there faint marks at the edges after merging?**
- A: Try increasing `overlap` (recommended to be at least 64) and ensure `blend_mode` is set to `gaussian`. Additionally, check if the `denoise` value during redrawing is too high, as excessive denoising can cause significant changes in tile content.
- A: Try increasing `overlap` (recommended to be at least 64) and ensure `blend_mode` is set to `gaussian` or `multi_band`. Additionally, check if the `denoise` value during redrawing is too high, as excessive denoising can cause significant changes in tile content.
- **Q: Does it support merging latent space?**
- A: Yes. However, due to the characteristics of the VAE encoder, overlapping merges in latent space use hard cutting, which may result in minor color differences upon decoding. It is generally recommended to perform the final merge in image space.
- A: Yes. However, due to the characteristics of the VAE encoder, overlapping merges in latent space may result in minor color differences upon decoding. It is generally recommended to perform the final merge in image space.
- **Q: Multi-band fusion is very slow. What should I do?**
- A: Multi-band fusion requires building image pyramids, which is indeed slower. For scenarios requiring real-time performance, it's recommended to use gaussian mode. You can also reduce the number of pyramid levels (default is 5 in the code).
- **Q: Optimal seamline computation produces abnormal cuts. What should I do?**
- A: Try increasing `seam_search_radius` to limit the seamline near the center, or directly use `seam_mode="middle"`.
- **Q: Why do I get multiple images as output even though I connected the nodes?**
- A: Ensure you are using `Advanced Tile Merger` and have correctly connected `tile_config`. If the output is still a list, check if you have connected an old node that does not support List after the Merger.
## 📊 Technical Specifications
- **Maximum Supported Dimensions**: Theoretically unlimited, depends on system memory
- **Maximum Tile Count**: 32×32 grid
- **Data Types**: Supports float32, float16, bfloat16
- **Device Support**: CUDA GPU (recommended), CPU (slower)
- **Dependencies**:
- torch >= 2.0.0
- numpy >= 1.20.0
- scipy >= 1.7.0 (for Gaussian filtering)
## 🔧 Development Notes
### Extension Interface
The plugin registers a custom type `TILE_CONFIG`, which can be extended via:
```python
from comfy.graph_utils import GraphBuilder
GraphBuilder.add_node_type("TILE_CONFIG", lambda x: isinstance(x, dict) and "splits" in x)
```
### Module Structure
```
ComfyUI-Advanced-Tile-Processing/
├── __init__.py # Node registration
├── nodes/
│ ├── tile_splitter.py # Splitter
│ ├── tile_merger.py # Merger
├── utils/
│ └── blending.py # Fusion algorithms
└── README_CN.md # Chinese documentation
```
## 🤝 Contribution and Feedback
Feel free to submit Issues or Pull Requests. If you find areas for improvement while using this project, please reach out.
## 📜 License
This project is open-source under the [Apache-2.0 license](https://github.com/QL-boy/comfyui-ps-plugin#Apache-2.0-1-ov-file).
This project is open-source under the [Apache-2.0 license](https://github.com/QL-boy/comfyui-ps-plugin#Apache-2.0-1-ov-file).