KJNodes/maskinggenerated

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

masks
MASK
width
512
height
512
padding
0
KJNodes

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 NameData TypeRequiredDefault ValueRange/OptionsDescription
masksMASKYes--masks (input parameter): The original batch of masks to be consolidated. Type is MASK.

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
widthINTYes5120 - 4096 (step: 64)width (input parameter): The width of the target consolidation tile, range 0 to 4096, adjustment step is 64.
heightINTYes5120 - 4096 (step: 64)height (input parameter): The height of the target consolidation tile, range 0 to 4096, adjustment step is 64.
paddingINTYes00 - 4096 (step: 1)padding (input parameter): The padding between masks during consolidation, range 0 to 4096, adjustment step is 1.

Output

Parameter NameData TypeDescription
MASKMASKMASK (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.

The Consolidate Masks node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…