ComfyUI Node
kubakub regions from masks
Turn any set of masks (SAM, painted, layers, ID passes) into named regions you can prompt one by one. One region per mask, named by the names list. Where new masks overlap, the smaller one wins. With base_regions the masks are patched into that atlas: on_top cuts them out of the regions below (a window out of a wall), underneath only fills pixels without a region. New regions are tagged with the base region they were cut from.
kubakub regions from masks
- masks
- base_regions
- matrix
- scope
- regions
- region_masks
- regions_json
- preview
- report
- scope
◄names►
◄patchon_top►
◄min_region_area64►
◄merge_small_regionstrue►
◄scope_masks►
◄split_masks►
◄tag_only_masks►
Categorykubakub/2d/regions
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | One mask per region (batch). Values over 0.5 are inside. | |
| names | STRING | One name per line in batch order, or one comma separated line. 'name = group' sets the group; otherwise the group is the name without its trailing number (W_F1_02 -> W_F1). Empty: mask_01.. | |
| patch | COMBO | on_top | With base_regions. on_top: new masks cut themselves out of the regions below. underneath: new masks only fill pixels no base region has. |
| min_region_area | INT | 640–100000000 | Regions smaller than this (pixels) are merged or dropped. |
| merge_small_regions | BOOLEAN | true | On: merge small regions into the neighbour with the longest shared border. Off: drop them. |
| base_regionsopt | KUBA_REGIONS | Existing atlas to patch. Its scope, names, groups and tags are kept. | |
| matrixopt | IMAGE | Background for the preview; also sets the size when there are no base_regions (masks of another size are resized, nearest). | |
| scopeopt | MASK | Pixels outside this mask are never part of a region. | |
| scope_masksopt | STRING | Names (wildcards ok) of masks that are no regions but the area regions may use. | |
| split_masksopt | STRING | Names of masks holding several shapes: one region per shape, <name>_01, _02 ... in group <name>. | |
| tag_only_masksopt | STRING | Names of masks that only tag the regions they cover. |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| regions | KUBA_REGIONS | Label map + region table for the kubakub region nodes. |
| region_masks | MASK | One mask per region; batch index = region_id. |
| regions_json | STRING | The region table as text (names, groups, tags, boxes, notes). |
| preview | IMAGE | One colour per group, region borders and ids over a grey copy of the matrix. |
| report | STRING | How many masks became how many regions and groups, pixels left without a region, and the notes (renamed, resized, merged or dropped masks). |
| scope | MASK | The scope that was used: 1 where regions may be (all 1 without a scope). |