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
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 Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
mask | MASK | Yes | - | - | The input mask to be separated. |
Parameters
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
mode | COMBO | Yes | convex_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_width | INT | Yes | 256 | 0.0 - 4096 (step: 1) | Sets the width size threshold for filtering regions. Range: 0 to 4096, step size 1. |
size_threshold_height | INT | Yes | 256 | 0.0 - 4096 (step: 1) | Sets the height size threshold for filtering regions. Range: 0 to 4096, step size 1. |
max_poly_points | INT | Yes | 8 | 3 - 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 Name | Data Type | Description |
|---|---|---|
| mask | MASK | Outputs 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.
Separate Masks Node Source Code Link
The Separate Masks node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.