KJNodes/maskinggenerated

Separate Masks(SeparateMasks)

This node is implemented based on computer vision libraries (such as OpenCV) and identifies independent connected regions by detecting contours in the input mask.

Separate Masks

mask
mask
size_threshold_width
256
size_threshold_height
256
mode
COMBO
max_poly_points
8
KJNodes

The Separate Masks node, implemented based on computer vision libraries (such as OpenCV), identifies independent connected regions by detecting contours within the input mask.

The Separate Masks node is a tool for processing masks. Its core function is to separate an input mask containing multiple discontinuous regions into multiple independent masks based on set conditions. It identifies connected regions within the mask, filters and segments them according to size or shape, thereby simplifying the management and subsequent operations of complex mask areas.

Node Functionality

This node is implemented based on computer vision libraries (such as OpenCV) and identifies independent connected regions by detecting contours within the input mask. It provides three separation modes (convex_polygons, area, box), each employing different algorithms to process and output masks. The processed output is a batch containing multiple independent masks, facilitating their separate use within the workflow.

Node Parameter Description - Separate Masks

Inputs

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
maskMASKYes--The input mask to be separated.

Parameters

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
modeCOMBOYesconvex_polygons"convex_polygons", "area", "box"Separation mode. Options: convex_polygons (approximates contours with convex polygons), area (filters based on region size), box (filters based on bounding box size).
size_threshold_widthINTYes2560.0 - 4096 (step: 1)Sets the width size threshold for filtering regions. Range: 0 to 4096, step size 1.
size_threshold_heightINTYes2560.0 - 4096 (step: 1)Sets the height size threshold for filtering regions. Range: 0 to 4096, step size 1.
max_poly_pointsINTYes83 - 32 (step: 1)Controls the maximum number of polygon vertices used to approximate contours in convex_polygons mode. Range: 3 to 32, step size 1.

Output

Parameter NameData TypeDescription
maskMASKOutputs multiple independent masks obtained after separation.

Use Cases

This node is highly useful in workflows involving image editing or region-specific generation. For example, when you have a semantic segmentation mask containing multiple scattered objects, you can use this node to separate each object into an independent mask. Then, you can apply different image processing nodes (such as inpainting, coloring, or style transfer) to each object individually, achieving fine-grained control.

Notes

Please note that the separation effectiveness of the node depends on the quality and connectivity of the input mask. Separation may not be precise for regions with blurred edges or severe adhesion. Additionally, the max_poly_points parameter affects the accuracy of the polygon approximation mode and should be adjusted according to the required level of detail.

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

Comments

Sign in with GitHub to join the discussion.

Loading comments…