Nodes/kubakub nodes/kubakub regions to mask
ComfyUI Node

kubakub regions to mask

Turn 'all the windows' into a mask any node can use

By kubakubkub·Created about a month ago·Updated 2 days ago· 10
kubakub regions to mask
  • regions
  • mask
  • names
  • region_masks
  • which regions
◄select*►
◄grow_px0►
◄feather_px0►
◄invertfalse►
◄per_region_masksfalse►

The region atlas is a nice data structure. ComfyUI doesn't speak it. kubakub regions to mask is the adapter - it takes the regions you built and hands you a plain MASK, which means any node in the ecosystem can now work on "the floor-1 windows" without knowing anything about facades.

That's the whole idea, and it's a bigger deal than it sounds. Every skill people have in this ecosystem is about masks: inpaint, composite, blur, colour correct, upscale only this part. None of that needed to be rewritten for projection mapping once you can get a mask out.

Picking regions

regions comes from any kubakub regions node - regions from masks, regions from id renders, regions from cryptomatte, and so on.

select is the plan selector syntax, and it's the same everywhere in the pack, so it's worth actually learning once:

*
group:Windows
W_F0_*
group:Windows, tag:left
tag:underside
!group:Windows

Wildcards on names, group:, tag:, name: or a bare name. Comma = OR, space = AND, ! = NOT. Empty or * means everything. The names output tells you what matched, which is the debugging tool - if names is empty, your selector didn't match anything and the mask is black.

Then the three edge treatments, which are exactly the ones you'd want:

  • grow_px - grow (> 0) or shrink (< 0) the mask, up to ±256.
  • feather_px - a soft edge that blurs both ways, inward and outward, over about that many pixels in total. Worth reading twice, because it's not the same as the usual "blur the mask outward" behaviour, and it's the reason a feathered region doesn't leave a hard rim of untouched pixels.
  • invert - everything except the selected regions. Useful for "keep the windows, change everything around them".

mask comes out as 1 on the selected regions, after grow, feather and invert. Wire it into ImageCompositeMasked, a VAE Encode (for inpaint), a ControlNet, a blur, kubakub colour match's mask input, or the director as a layer's clip mask.

The optional output that eats RAM

per_region_masks (off by default) turns on region_masks: one mask per selected region, in the order of names, before grow, feather and invert. That distinction matters - the combined mask is post-processing, the per-region batch is raw. Which is what you want when you're going to do something different per region downstream.

The tooltip is refreshingly honest about the cost: regions × width × height × 4 bytes. 100 regions at 3840×2160 is 3.3 GB of RAM. The node refuses outright above 4 GB and asks you to narrow the selection. That's not a bug - it's a pack that would rather stop than swap your machine to death.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/kubakubkub/ComfyUI_KubaNodes
python -m pip install -r ComfyUI_KubaNodes/requirements.txt

Manager → search kubakub nodes, or comfy node install comfyui-kubanodes. ComfyUI 0.37.0 or newer, and OpenCV is the only added dependency. No models, no Blender, no ffmpeg - this node runs on a plain install.

Things worth knowing

A node connected to region_masks while the switch is off stops with an error. The message says so, but it's an easy one to hit while re-wiring: the switch is a memory guard, not a preference.

Feather and grow are not interchangeable. Feather softens the edge; grow extends the region. A SAM mask usually needs one or two pixels of grow, because segmentation hugs the object and the inpaint will leave a one-pixel halo of the old content. Then a small feather on top.

This is how you get regions into ordinary ComfyUI workflows. You don't need the sampler to benefit from the regions nodes. Build the atlas once with masks or an ID render, pull "all the windows" out as a mask, and use it with whatever inpaint or detail pipeline you already trust. There's nothing stopping you from mixing this pack's per-region logic with a plain, well-understood graph for the actual generation - and honestly, for a first project, that's a good way to start.

Categorykubakub/2d/regions

Inputs (6)

NameTypeDefaultDescription
regionsKUBA_REGIONSFrom any kubakub regions node (e.g. regions from masks).
selectSTRING*The regions that become the mask. * = all. Written as in kubakub region plan: names with wildcards ('W_F1_*'), 'group:Windows', 'tag:front', 'region:3-7'; comma or Enter = or, space = and, '!' = not.
grow_pxINT0-256–256Grow (> 0) or shrink (< 0) the mask.
feather_pxINT00–256Soft edge: blurs the edge both ways, inwards and outwards, over about this many pixels in total.
invertBOOLEANfalseOn: the mask covers everything except the selected regions.
per_region_masksoptBOOLEANfalseOn: region_masks gives one mask per selected region. Takes regions x width x height x 4 bytes of RAM (100 regions at 3840x2160 = 3.3 GB), so it is off until you need it.

Outputs (4)

NameTypeDescription
maskMASK1 on the selected regions (after grow, feather, invert).
namesSTRINGThe matching region names.
region_masksMASKOne mask per selected region (batch), in the order of names, before grow, feather and invert. Needs per_region_masks on. Above 4 GB of RAM the node stops and asks for a narrower select.
which regionsSTRINGThe text of 'which regions' as it is: connect it to the 'which regions' field of a kubakub shader, region sampler, mask field ... so one choice serves them all.