Nodes/ComfyUI-Region-Edit-Toolkit/图像分区 · 遮罩有效性检查
ComfyUI Node

图像分区 · 遮罩有效性检查

A tiny gate that saves you from a wasted five-minute render

By Liu-Bot24·Created about a month ago·Updated 21 days ago· 1
图像分区 · 遮罩有效性检查
  • mask
  • validated_mask
  • mask_report_json
support_threshold0.001
minimum_fraction0.0050

The most expensive failure in a mask-based edit isn't a wrong edit - it's an edit that never happens at all, silently. Your detector returned an empty mask, or the protection ate the whole target, and your workflow happily "edited" nothing, sampling five minutes at full res and returning the input unchanged. RegionEditMaskContentGate is the cheap insurance against that: it checks whether a mask actually contains enough editable content, and throws an error if it doesn't, so the run stops instantly instead of wasting a render.

The docstring for the underlying implementation says it all: "Stop the run instead of silently returning the unchanged source image." That's the entire product. It's a two-input, two-output validator that slots into the Region Edit Toolkit wherever a mask is about to drive something expensive.

How it works

It measures the fraction of the mask that exceeds support_threshold (default 0.001 - i.e., "is actually nonzero") and compares it against minimum_fraction (default 0.005, i.e. 0.5% of the image). If the supported fraction is below the minimum, it raises a clear error telling you the mask is empty or too small - with the actual fraction in the message, so you can see how close you were. If it passes, it echoes the mask back through validated_mask untouched, along with a mask_report_json that records the gate result, the threshold, and the measured fraction.

That pass-through design is the useful part: you can drop this node inline anywhere in a mask pipeline - after RegionEditInteractiveMaskCompose, after a difference mask, after a detection - and it costs you nothing when things are fine. It only ever speaks up when they're not.

Inputs that matter

  • mask - whatever mask is about to drive the edit.
  • minimum_fraction - the real knob. 0.5% of the image is a low bar (a small but legitimate fix like a stray wire passes); if you're editing something genuinely tiny, lower it - but then you're accepting that the model will be working with almost no context.
  • support_threshold - leave at the default. It just defines "what counts as content."

Outputs: validated_mask (pass-through) and mask_report_json.

Install

ComfyUI Manager → search "Region Edit Toolkit" (package ID native-region-tile-planner-merge) → install → restart. Or git clone https://github.com/Liu-Bot24/ComfyUI-Region-Edit-Toolkit.git into custom_nodes, pip install -r requirements.txt into ComfyUI's Python, restart. Python 3.10+, deps numpy/Pillow/scipy/argostranslate, no models.

Gotchas

There's a trap hiding in its own design: because it's a hard error, a gate that's too strict will brick a workflow that legitimately edits a tiny region - the run stops, and if you've chained a few masks, the error message might not tell you which one died. Read the message, check mask_report_json's fraction, and lower minimum_fraction deliberately if the region is genuinely small. The pack's broader strictness philosophy (protection wins, sizes must match, errors over silent no-ops) is the same design DNA - once you've accepted that, a gate node like this is obviously the right thing to have in the graph.

CategoryRegion Edit Toolkit/Mask

Inputs (3)

NameTypeDefaultDescription
maskMASK
support_thresholdFLOAT0.0010–1
minimum_fractionFLOAT0.00500.0001–1

Outputs (2)

NameTypeDescription
validated_maskMASK
mask_report_jsonSTRING