Nodes/ComfyUI_KubaNodes/kubakub regions from matrix / masks
ComfyUI Node

kubakub regions from matrix / masks

Splits a facade matrix (the full projection image at delivery size) into regions, so each window, pier or wall part can be treated on its own. color_regions: one region per flat colour (per connected patch when split_disconnected is on). line_drawing: the closed cells between lines. mask_folder: one region per PNG, named after the file (subfolders too). Scope masks limit where regions may be, split masks give one region per separate shape. Repeated elements get a shared group_id; every region is tagged with the larger masks that cover it (floor, facade ...).

By kubakubkub·Created 15 days ago·Updated 3 days ago· 9
kubakub regions from matrix / masks
  • matrix
  • scope
  • masks
  • regions_json
  • preview
  • scope
  • regions
  • report
◄modecolor_regions►
◄min_region_area400►
◄merge_small_regionstrue►
◄color_tolerance24►
◄split_disconnectedtrue►
◄group_tolerance0.08►
◄recursivetrue►
◄group_bystem►
◄output_maskstrue►
◄line_threshold0.50►
◄line_polarityauto►
◄line_gap_close_px1►
◄color_names►
◄mask_folder►
◄scope_masks►
◄split_masks►
◄tag_only_masks►
Categorykubakub/2d/regions

Inputs (19)

NameTypeDefaultDescription
matrixIMAGEThe facade matrix: the full projection image at delivery size (e.g. a 3840x2160 PNG). Only the first image of a batch is used.
modeCOMBOcolor_regionsWhere the regions come from. color_regions: flat colour fills in the matrix. line_drawing: closed cells of a line drawing. mask_folder: a folder of PNG masks (e.g. exported from After Effects).
min_region_areaINT4000–100000000Regions smaller than this (in pixels) are merged or dropped.
merge_small_regionsBOOLEANtrueOn: merge small regions into the neighbour with the longest shared border. Off: drop them (they stay unassigned).
color_toleranceINT240–442color_regions: colours closer than this (RGB distance, 0-255 units) count as the same fill.
split_disconnectedBOOLEANtruecolor_regions: on = every separate patch of a colour is its own region (each window), off = one region per colour.
group_toleranceFLOAT0.080–0.5How different two regions may be (relative bbox size, 1 - shape IoU) and still share a group_id. 0 = identical only.
recursiveBOOLEANtruemask_folder: also read PNGs in subfolders (Groups/, Windows/ ...).
group_byCOMBOstemmask_folder: group_id from the file name without its trailing number (stem) or from the subfolder name (folder).
output_masksBOOLEANtrueOff: the masks output is a single empty mask, saving RAM when only the regions output is used.
line_thresholdFLOAT0.500–1line_drawing: brightness that separates lines from paper.
line_polarityCOMBOautoline_drawing: auto takes whichever of dark/light is the minority as the lines.
line_gap_close_pxINT10–32line_drawing: thicken lines by this much first, so small gaps don't leak one cell into the next.
color_namesoptSTRINGcolor_regions: name the groups by matrix colour. Every region of that colour gets the name as group_id.
mask_folderoptSTRINGmask_folder: folder of PNG masks (alpha or white = inside). 'windows_03.png' becomes region 'windows_03' in group 'windows'. Empty: the sample facade's masks at the matrix size, so the node runs as it is.
scope_masksoptSTRINGmask_folder: masks (names or wildcards, comma or one per line) that are not regions but the area regions may use. Nothing outside their union is ever a region.
split_masksoptSTRINGmask_folder: masks holding several separate shapes. Each shape becomes a region <name>_01, _02 ... in reading order, all in group <name>.
tag_only_masksoptSTRINGmask_folder: masks that only tag the regions they cover and are no region themselves.
scopeoptMASKAny mode: pixels outside this mask are never part of a region.

Outputs (6)

NameTypeDescription
masksMASKOne mask per region; batch index = region_id.
regions_jsonSTRINGThe region table as text: ids, groups, tags, boxes and notes.
previewIMAGEThe matrix in grey with one colour per group, region borders and ids.
scopeMASK1 where regions may be (all 1 without a scope).
regionsKUBA_REGIONSLabel map + region table for the kubakub region nodes.
reportSTRINGHow many regions and groups were found, pixels left without a region, and the notes (merged or dropped regions, the sample used when no folder is given).