Nodes/ComfyUI-NynxzNodes/Regions from Masks
ComfyUI Node

Regions from Masks

Turn a mask batch into numbered regions a LoRA can be gated to

By Nynxz·Created 10 months ago·Updated a day ago· 0
Regions from Masks
  • masks
  • regions
  • regions
grow12
feather8
denoise1.00
fitstretch

A LoRA can't be masked. Conditioning can, but a LoRA is a weight patch - merge two character LoRAs and both deltas fire on every token, blending identities no matter how you word the prompt. The Regions group in ComfyUI-NynxzNodes solves that by never merging the LoRA at all: it runs each one as a live side branch with a per-token gate, so character B's delta never touches character A's tokens. And the first node in that pipeline is Regions from Masks - it takes a MASK batch and turns each mask into a numbered region that a LoRA can later be bound to.

The intended source is ComfyUI core's SAM3 Detect with individual_masks on: point it at the image with a text conditioning naming what to find, and it hands back one mask per detected object. Anything that emits masks works the same - BiRefNet, a matte, a mask you painted by hand. One region per mask in the batch, in batch order.

The settings that matter

  • grow (default 12px) - dilates each mask outward. A segmenter hugs the silhouette it sees, and a LoRA gated to exactly that silhouette can restyle the face but not the hair, jaw or coat outline - the pixels that carry identity at a glance, sitting just past the boundary. This is the first knob to raise when the face comes out right but the outline is wrong. Worth knowing the projection math: Krea 2 gates on a (H/16, W/16) canvas, so a few pixels of grow are sub-token adjustments - think in tens, not twos.
  • feather (default 8px) - softens the mask edge so the LoRA hands over gradually instead of switching on across a single token (which reads as a seam).
  • denoise (default 1) - how much Region Latent may rewrite these areas (1 = rebuild freely, right when masks are subjects you're replacing). Only Region Latent reads it, and Region Denoise overrides it per region.
  • fit (default stretch) - how the mask's frame maps to the generated canvas. stretch is right when the mask was drawn on the image being edited at the framing being generated - the usual case.

You can also chain: the optional regions input appends these masks to an existing set, so one segmenter pass per subject is fine and you merge them downstream.

The SAM3 trap (this costs an evening)

SAM3's prompt supports category:N, and N defaults to 1. A prompt of person returns exactly one mask no matter what individual_masks says, which looks for all the world like a broken node. Write person:2 for two of the same thing. Two different subjects need no syntax - woman, man is two categories and already yields two masks.

Also worth internalizing: regions are numbered, not named. The number is the mask's position in the batch, and every other node indexes by it. A binding pointing at region 2 is the second mask, full stop.

Install

In Nynxz's Custom Nodes: ComfyUI Manager → search "NynxzNodes" (registry build is smoothest - a hand clone needs pnpm install && pnpm build since the UI's web/ is gitignored), or git clone https://github.com/Nynxz/ComfyUI-NynxzNodes into ComfyUI/custom_nodes. No pip dependencies, but the whole Regions group is Krea 2 only and experimental - Regions Apply will refuse to run on any other architecture. And SAM3's ComfyUI nodes need Triton, which is the usual Windows stumbling block.

CategoryNynxz/Regions

Inputs (6)

NameTypeDefaultDescription
masksMASKOne mask per region. SAM3 Detect's `masks` output with `individual_masks` on is the intended source: one mask per detected object.
growINT120–256Dilate each mask, in pixels. A segmenter hugs the silhouette, and a LoRA gated to exactly that cannot change the hair, jaw or clothing outline — the parts that carry identity at a glance. Raise this first if the face is right but the outline is wrong.
featherINT80–256Soften each mask's edge, in pixels, so the LoRA hands over gradually instead of switching on across a single token.
denoiseFLOAT1.000–1How much of these regions Region Latent may rewrite. 1 = rebuild freely, which is right when the masks are subjects you are replacing; lower it when they are areas you are only restyling. Region Denoise overrides it per region. Only Region Latent reads it.
fitCOMBOstretchHow the mask's frame maps onto the generated canvas. `stretch` is right when the mask was drawn on the image being edited at the framing being generated, which is the usual case. The others preserve aspect for a mask that came from a differently-shaped source.
regionsoptNYNXZ_REGIONSChain from another regions node to add these to an existing set.

Outputs (1)

NameTypeDescription
regionsNYNXZ_REGIONSWire into Region LoRAs to bind a LoRA to each one. Region Inspect shows what is on it.