Consolidate Masks(ConsolidateMasksKJ)
This node takes a batch of masks as input and analyzes the bounding box of the valid area for each mask.
Consolidate Masks KJ
The Consolidate Masks node receives a batch of masks as input and analyzes the bounding box of the effective area for each mask.
The Consolidate Masks node is a tool for optimizing and managing batches of masks. Its core function is to intelligently merge multiple independent masks into tiles of a specified size, thereby reducing the number of processing batches and improving the efficiency of subsequent processing.
Node Functionality
This node receives a batch of masks as input and analyzes the bounding box of the effective area for each mask. Its core algorithm searches for the largest group of masks that can fit within the specified width and height (including padding) and merges them. This process iterates until no more masks can be combined, ultimately outputting a new, consolidated batch of masks.
Node Parameter Description - Consolidate Masks
Connection Inputs (Inputs)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
masks | MASK | Yes | - | - | masks (input parameter): The original batch of masks to be consolidated. Type is MASK. |
Control Parameters (Parameters)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
width | INT | Yes | 512 | 0 - 4096 (step: 64) | width (input parameter): The width of the target consolidation tile, range 0 to 4096, adjustment step is 64. |
height | INT | Yes | 512 | 0 - 4096 (step: 64) | height (input parameter): The height of the target consolidation tile, range 0 to 4096, adjustment step is 64. |
padding | INT | Yes | 0 | 0 - 4096 (step: 1) | padding (input parameter): The padding between masks during consolidation, range 0 to 4096, adjustment step is 1. |
Output
| Parameter Name | Data Type | Description |
|---|---|---|
| MASK | MASK | MASK (output parameter): The new, optimized batch of masks output after consolidation. |
Usage Scenarios
This node is very useful in workflows that require processing a large number of small objects or areas separately, such as batch repairing multiple flaws in an image or generating content for multiple independent elements. You can input multiple masks obtained from segmentation into this node, and it will automatically pack them into fewer tiles. You can then feed the consolidated batch of masks into an image inpainting node for unified processing, thereby avoiding separate inference for each mask and saving computational resources.
Notes
This node requires the input masks to be binarized. Its consolidation logic is based on the bounding rectangles of the masks, so the consolidation efficiency may be affected for masks with extremely irregular or scattered shapes. The size of the output mask batch is determined by the number of input masks and the consolidation results.
Consolidate Masks Node Source Code Link
The Consolidate Masks node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.