Nodes/ComfyUI_KubaNodes/kubakub regions from masks
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.

By kubakubkub·Created 15 days ago·Updated 3 days ago· 9
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)

NameTypeDefaultDescription
masksMASKOne mask per region (batch). Values over 0.5 are inside.
namesSTRINGOne 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..
patchCOMBOon_topWith 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_areaINT640–100000000Regions smaller than this (pixels) are merged or dropped.
merge_small_regionsBOOLEANtrueOn: merge small regions into the neighbour with the longest shared border. Off: drop them.
base_regionsoptKUBA_REGIONSExisting atlas to patch. Its scope, names, groups and tags are kept.
matrixoptIMAGEBackground for the preview; also sets the size when there are no base_regions (masks of another size are resized, nearest).
scopeoptMASKPixels outside this mask are never part of a region.
scope_masksoptSTRINGNames (wildcards ok) of masks that are no regions but the area regions may use.
split_masksoptSTRINGNames of masks holding several shapes: one region per shape, <name>_01, _02 ... in group <name>.
tag_only_masksoptSTRINGNames of masks that only tag the regions they cover.

Outputs (6)

NameTypeDescription
regionsKUBA_REGIONSLabel map + region table for the kubakub region nodes.
region_masksMASKOne mask per region; batch index = region_id.
regions_jsonSTRINGThe region table as text (names, groups, tags, boxes, notes).
previewIMAGEOne colour per group, region borders and ids over a grey copy of the matrix.
reportSTRINGHow many masks became how many regions and groups, pixels left without a region, and the notes (renamed, resized, merged or dropped masks).
scopeMASKThe scope that was used: 1 where regions may be (all 1 without a scope).