Add files via upload

This commit is contained in:
QL-boy
2026-01-17 20:25:45 +08:00
committed by GitHub
parent 9757111567
commit ec08911175
2 changed files with 262 additions and 68 deletions
+131 -34
View File
@@ -1,204 +1,301 @@
# ComfyUI-Advanced-Tile-Processing
[中文](README_CN.md) [English](README.md)
[中文](https://www.google.com/search?q=README_CN.md "null") [English](https://www.google.com/search?q=README.md "null")
**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.
- **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
1. **Environment Requirements**: ComfyUI 0.4.0+, Python 3.10+, PyTorch 2.0+.
2. Navigate to your ComfyUI custom nodes directory:
```
cd ComfyUI/custom_nodes/
```
3. Clone this repository:
```
git clone https://github.com/QL-boy/ComfyUI-Advanced-Tile-Processing.git
git clone [https://github.com/QL-boy/ComfyUI-Advanced-Tile-Processing.git](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`: 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`: 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.
- **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.
- 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 Principles
### 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
### 2. Multi-Mode Fusion Techniques
#### 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}} $$
$$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} $$
$$E_{\text{total}} = E_{\text{color}} + \lambda \cdot E_{\text{geometry}}$$
Where:
- $E_{color}$ is color difference
- $E_{geometry}$ is geometric constraint (staying close to centerline)
- $E_{\text{color}}$ is color difference
- $E_{\text{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 $$
$$I_{\text{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" |
| | |
|---|---|
|**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质量升级
![](./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` 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.
- **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)
- 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
@@ -216,4 +313,4 @@ Feel free to submit Issues or Pull Requests. If you find areas for improvement w
## 📜 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 "null").
+131 -34
View File
@@ -1,204 +1,301 @@
# ComfyUI-Advanced-Tile-Processing
[中文](README_CN.md) [English](README.md)
[中文](https://www.google.com/search?q=README_CN.md "null") [English](https://www.google.com/search?q=README.md "null")
**ComfyUI-Advanced-Tile-Processing** 是一套专为 ComfyUI 设计的高级自定义节点插件。它旨在解决超高分辨率图像生成和处理中的显存瓶颈(VRAM OOM),通过智能分块(Tiling)与多种高级融合技术的无缝合并(Merging),让您能够在普通消费级显卡上稳定处理 4K、8K 甚至更高规格的图像。
## 🌟 核心特性
- **智能维度感知 (Smart Dimension Awareness)**:自动计算最优切片坐标。支持"边缘回退"策略,确保分块完全覆盖原始图像,无需引入黑边(Padding)从而避免模型产生伪影。
- **多种高级融合技术**:支持线性混合、高斯混合、多频段融合(Laplacian Pyramid)和直接拼接四种模式。
- **历史图匹配 (Histogram Matching)**:基于Reinhard算法,在融合前对相邻分块进行颜色分布匹配,消除色差。
- **最优接缝线计算 (Optimal Seamline)**:支持动态规划和中间线两种接缝模式,可限制搜索半径,自动寻找最小能量路径,避免切割重要内容。
- **元数据驱动流 (Metadata-Driven Workflow)**:Splitter 生成唯一的 `TILE_CONFIG` 对象,包含原始尺寸、缩放因子及坐标。Merger 自动读取配置一键还原,用户无需手动对齐参数。
- **深度兼容性**:完美适配 ComfyUI 的列表执行机制。支持将分块作为 `BATCH` 提交以获得最高推理速度,或作为 `LIST` 提交以支持循环节点处理。显存不足的情况下推荐 `LIST` 替代 `BATCH`。
- **高性能架构**:完全基于 PyTorch 张量运算,GPU 加速,保证处理大图时性能在线。
- **动态尺寸支持 (Tiled Upscale)**:支持动态尺寸调整(Tiled Upscale),在分块后进行放大处理。Merger 能够自动检测片段尺寸变化并动态调整画布大小。
## 🛠 安装说明
1. **环境要求**:ComfyUI 0.4.0+,Python 3.10+,PyTorch 2.0+。
2. 进入您的 ComfyUI 自定义节点目录:
```
cd ComfyUI/custom_nodes/
```
3. 克隆本仓库:
```
git clone https://github.com/QL-boy/ComfyUI-Advanced-Tile-Processing.git
git clone [https://github.com/QL-boy/ComfyUI-Advanced-Tile-Processing.git](https://github.com/QL-boy/ComfyUI-Advanced-Tile-Processing.git)
```
4. 重启 ComfyUI。
## 🧩 节点详解
### 1. 🔧 Advanced Tile Splitter (高级分块器)
![](./nodes/tile_splitter.png)
将输入的大图或 Latent 空间分割成重叠的小块。
- **输入端口**:
- `image`: (可选) 原始图像。
- `latent`: (可选) 潜在空间数据。
- **核心参数**:
- `tile_size`: 分块分辨率(如 512, 1024)。
- `overlap`: 两个分块之间的重叠像素。建议设为 `tile_size` 的 10% 及以上以获得最佳融合效果。
- `rows`: 固定行数(设为0时自动计算)。
- `columns`: 固定列数(设为0时自动计算)。
- `normalize`: 是否将尺寸对齐到64的倍数(推荐开启以保证兼容性)。
- **输出端口**:
- `tile_config`: 核心配置文件(必需连接至 Merger),包含合并所需的所有元数据。
- `tiles_image_batch`: 将所有分块合并为一个 Batch Tensor,适合高性能采样。
- `tiles_image_list`: (List 模式) 分块图像列表,触发 ComfyUI 循环执行。
- `tiles_latent_batch`: 合并的 Latent Batch。
- `tiles_latent_list`: (List 模式) 分块 Latent 列表。
### 2. 🔧 Advanced Tile Merger (高级合并器)
![](./nodes/tile_merger.png)
根据分块配置将处理后的片段无缝还原。
- **输入端口**:
- `tile_config`: 由 Splitter 输出的配置对象。
- `processed_tiles_image`: (可选) 处理后的图像片段。
- `processed_tiles_latent`: (可选) 处理后的 Latent 片段。
- **核心参数**:
- `blend_mode`: 融合模式
- `linear`: 线性混合。
- `gaussian` (默认): 高斯权重混合,中心权重高,边缘平滑衰减,融合效果最自然。
- `multi_band`: 多频段融合(Laplacian Pyramid),最高质量的融合效果,适用于高对比度边缘。
- `none`: 硬边缘拼接(会有明显接缝)。
- `blend_strength`: 融合强度,控制羽化程度。
- `seam_mode`: 接缝线模式
- `optimal`: 动态规划计算最小能量路径。
- `middle`: 直接使用重叠区域的中心线。
- `histogram_matching`: 是否启用历史图匹配,消除相邻分块间的色差。
- `seam_search_radius`: 接缝线搜索半径,限制接缝线在中心线附近波动。
- **输出端口**:
- `merged_image`: 合并后的完整图像。
- `merged_latent`: 合并后的完整 Latent。
- **内部机制**:
节点会自动解包 `LIST` 输入。如果您的上游是循环节点,请确保所有分块均已处理完成再输入 Merger。
- 内部机制:
节点会自动解包 LIST 输入。如果您的上游是循环节点,请确保所有分块均已处理完成再输入 Merger。
## 📖 核心算法原理
### 1. 分块策略
分块器采用智能坐标计算,确保:
- 完全覆盖原始图像,无遗漏区域
- 重叠区域均匀分布
- 支持固定行列数或自动计算
- 支持尺寸对齐到8或64的倍数
### 2. 多模式融合技术
#### A. 线性混合 (Linear Blending)
在重叠区域进行简单的线性插值,快速但可能在边缘产生模糊。
#### B. 高斯混合 (Gaussian Blending)
使用高斯核函数生成权重掩码,中心权重高,边缘平滑衰减:
$$ M(x,y) = e^{-\frac{(x-x_c)^2+(y-y_c)^2}{2\sigma^2}} $$
$$M(x,y) = e^{-\frac{(x-x_c)^2+(y-y_c)^2}{2\sigma^2}}$$
#### C. 多频段融合 (Multi-band Blending)
基于拉普拉斯金字塔的高质量融合:
1. 构建图像的高斯金字塔和拉普拉斯金字塔
2. 在每一层分别融合
3. 从顶层重建图像
优势:
- 保留高频细节
- 平滑过渡低频信息
- 消除鬼影效应
#### D. 最优接缝线 (Optimal Seamline)
通过动态规划计算最小能量路径:
$$ E_{total} = E_{color} + \lambda \cdot E_{geometry} $$
$$E_{\text{total}} = E_{\text{color}} + \lambda \cdot E_{\text{geometry}}$$
其中:
- $E_{color}$ 为颜色差异
- $E_{geometry}$ 为几何约束(保持接近中心线)
- $E_{\text{color}}$ 为颜色差异
- $E_{\text{geometry}}$ 为几何约束(保持接近中心线)
- $\lambda$ 为平衡参数
### 3. 历史图匹配 (Histogram Matching)
基于Reinhard算法,将源图像的统计特性匹配到参考图像:
$$ I_{matched} = \frac{(I - \mu_s)}{\sigma_s} \times \sigma_t + \mu_t $$
$$I_{\text{matched}} = \frac{(I - \mu_s)}{\sigma_s} \times \sigma_t + \mu_t$$
其中:
- $\mu_s, \sigma_s$ 为源图像的均值和标准差
- $\mu_t, \sigma_t$ 为目标图像的均值和标准差
### 4. Latent空间合并
对于Latent空间,采用简化的"中心裁剪"策略:
- 每个分块在重叠区域内取中心部分
- 直接拼接到画布,无融合
- 8倍下采样对应处理
## 🚀 使用建议
### 最佳实践配置
| 场景 | 推荐参数 |
|------|----------|
| 普通图像拼接 | overlap=64, blend_mode="gaussian", blend_strength=0.25 |
| 高对比度图像 | overlap=128, blend_mode="multi_band", blend_strength=0.3 |
| 有显著色差 | 开启histogram_matching,seam_mode="optimal" |
| 速度优先 | blend_mode="linear", seam_mode="middle" |
| | |
|---|---|
|**场景**|**推荐参数**|
|普通图像拼接|overlap=64, blend_mode="gaussian", blend_strength=0.25|
|高对比度图像|overlap=128, blend_mode="multi_band", blend_strength=0.3|
|有显著色差|开启histogram_matching,seam_mode="optimal"|
|速度优先|blend_mode="linear", seam_mode="middle"|
### 性能优化
1. **Batch模式**:当分块数较少(≤4)且显存充足时,使用Batch模式获得最高性能
2. **List模式**:分块数多或显存紧张时,使用List模式逐个处理
3. **搜索半径**:设置适当seam_search_radius(如10-20)可加速最优接缝计算
### 常见工作流
### SDXL 经典分块采样高清修复复刻
![](<./example_workflows/SDXL 经典分块采样高清修复复刻.png>)
### Z-Image质量升级
![](./example_workflows/Z-Image质量升级.png)
## ⚠️ 常见问题 (FAQ)
- **Q: 为什么合并后的图边缘还是有淡淡的印子?**
- A: 尝试增加 `overlap` (建议不低于 64) 并确保 `blend_mode` 设为 `gaussian` 或 `multi_band`。同时,检查重绘时的 `denoise` 是否过高,过高的降噪会导致分块内容产生剧烈变化。
- **Q: 支持 Latent 空间合并吗?**
- A: 支持。但由于 VAE 编码器的特性,Latent 空间的重叠合并采用硬切割,可能会在 Decode 后出现微小色差,通常推荐在 Image 空间执行最终合并。
- **Q: 多频段融合速度很慢怎么办?**
- A: 多频段融合需要构建图像金字塔,确实较慢。对于实时性要求高的场景,建议使用gaussian模式。也可以减少金字塔层数(代码中默认为5层)。
- **Q: 最优接缝线计算出现异常切割怎么办?**
- A: 可尝试增加 `seam_search_radius` 限制接缝线在中心附近,或直接使用 `seam_mode="middle"`。
- **Q: 为什么我连接了节点却输出了多张图?**
- A: 请确保您使用的是 `Advanced Tile Merger` 并正确连接了 `tile_config`。如果输出依然是列表,请检查是否在 Merger 之后又连接了不支持 List 的旧版节点。
## 📊 技术规格
- **最大支持尺寸**:理论无限制,取决于系统内存
- **分块最大数量**:32×32网格
- **数据类型**:支持float32, float16, bfloat16
- **设备支持**:CUDA GPU(推荐),CPU(较慢)
- **依赖库**:
- torch >= 2.0.0
- numpy >= 1.20.0
- scipy >= 1.7.0(用于高斯滤波)
- torch >= 2.0.0
- numpy >= 1.20.0
- scipy >= 1.7.0(用于高斯滤波)
## 🔧 开发说明
### 扩展接口
插件注册了自定义类型 `TILE_CONFIG`,可通过以下方式扩展:
```python
```
from comfy.graph_utils import GraphBuilder
GraphBuilder.add_node_type("TILE_CONFIG", lambda x: isinstance(x, dict) and "splits" in x)
```
### 模块结构
```
ComfyUI-Advanced-Tile-Processing/
├── __init__.py # 节点注册
@@ -216,4 +313,4 @@ ComfyUI-Advanced-Tile-Processing/
## 📜 许可说明
本项目基于 [Apache-2.0 license](https://github.com/QL-boy/comfyui-ps-plugin#Apache-2.0-1-ov-file) 许可证开源。
本项目基于 [Apache-2.0 license](https://github.com/QL-boy/comfyui-ps-plugin#Apache-2.0-1-ov-file "null") 许可证开源。