ComfyUI Extension: ComfyUI-Advanced-Tile-Processing

Authored by QL-boy

Created

Updated

1 stars

Advanced tiling plugin for ComfyUI solving VRAM limitations in 4K/8K+ image generation using intelligent tiling and seamless weighted fusion with multiple blending modes.

Custom Nodes (0)

    README

    ComfyUI-Advanced-Tile-Processing

    中文 English

    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.

    🌟 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.
    • 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.
    • 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/
    
    1. 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)
    
    1. Restart ComfyUI.

    🧩 Node Details

    1. 🔧 Advanced Tile Splitter (Splitter)

    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.
    • Output Ports:

      • 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.

    2. 🔧 Advanced Tile Merger (Merger)

    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.
    • 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)

    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. 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.

    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

    Z-Image Quality Upgrade

    ⚠️ 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.
    • Q: Does it support merging latent 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: 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.

    🤝 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.