Nodes/ComfyUI-I2I-slim/Segment (Mask Ops)
ComfyUI Node

Segment (Mask Ops)

Build a mask from a color channel, a curve, or a sentence

By GeraldWie·Created about a year ago·Updated about a year ago· 0
Segment (Mask Ops)
  • image
  • mask
  • mask_image
  • mask
  • mask mapping
text
separate_mask0
text_sigma30
use_text0
blend_percentage0.00
black_level0.0
mid_level127.5
white_level255.0
channel
shrink_grow0
invert0
blur_radius5.0

Every cut-paste workflow starts with a mask, and most people hand-paint theirs. Segment (Mask Ops) is the node for when you'd rather not - it builds a mask from an image's color channel, shapes it with a levels curve, and can even generate one from a text prompt. It's the front door of the whole pack: everything else in ComfyUI-I2I-slim is downstream of what this node produces.

Two ways to build a mask

Image mode is the everyday path. Pick a channel (red, green, or blue), then set black_level / mid_level / white_level - that's a classic levels curve; anything below black is cut, above white is kept, and the mid point bends the falloff. From there you get the usual cleanup dials: invert flips it, shrink_grow erodes (negative) or dilates (positive) up to ±128, and blur_radius feathers the edge so your inpaint doesn't leave a hard seam. blend_percentage controls how much of the original image shows through in the mask output - 0 for a clean mask, higher to preview the region in context.

Text mode is the party trick. Flip use_text to 1 and the mask comes from a CLIPSeg segmentation model (CIDAS/clipseg-rd64-refined) run on your text prompt - "the red car", "the person on the left", that kind of thing. text_sigma controls how soft the resulting region is. Fair warning: this is the one place the pack needs something you don't already have. First run downloads the CLIPSeg weights from Hugging Face into ComfyUI/models/clipseg, and it requires the transformers package - which, go figure, is not in requirements.txt.

The feature that makes the pack work

Set separate_mask to 1 and the mask gets split into its connected components - every separate blob becomes its own item in the batch, with a matching mapping output so nothing gets mixed up. That's what lets the downstream Cut and Paste nodes handle several regions (faces, objects, garments) in a single pass, each cropped, generated, and pasted independently. Without this, multi-region work means running the chain once per blob. This is your multi-region inpainting switch.

Outputs and wiring

  • mask_image (IMAGE) - wire this into Cut (Inpaint Segments), which wants an image-typed mask.
  • mask (MASK) - for anything that wants a genuine mask, like a sampler's inpaint conditioning.
  • mask mapping (MASK_MAPPING) - the bookkeeping that keeps batch regions straight; pair it with Cut and Paste when separate_mask is on.

Installing it

The node is part of ComfyUI-I2I-slim, GeraldWie's slimmed fork of ManglerFTW's ComfyI2I. ComfyUI Manager:

Manager → Install Custom Nodes → search "ComfyUI-I2I-slim" → Install → Restart

or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/GeraldWie/ComfyUI-I2I-slim
cd ComfyUI-I2I-slim
pip install -r requirements.txt

Two things about that requirements file: it lists tensorflow and scikit-image that the code never imports (leftovers - skip them), and it omits transformers, which text mode needs. Also note the node auto-installs scipy at runtime the first time you run it if it's missing. Handy, mildly cursed.

Common issues

  • Text mode fails on first run - it's downloading the CLIPSeg model or missing transformers. pip install transformers, check your network, and give it a minute.
  • Mask comes out wrong-shaped - check your levels; a white_level of 255 with a mid_level of 127.5 is the neutral starting point, and moving mid is the fastest way to break a mask.
  • Blobs getting merged - run separate_mask on and use the mask mapping output; that's exactly what it exists for.
CategoryI2I-slim

Inputs (14)

NameTypeDefaultDescription
imageIMAGE
textSTRING
separate_maskINT00–1
text_sigmaINT300–150
use_textINT00–1
blend_percentageFLOAT0.000–1
black_levelFLOAT0.00–255
mid_levelFLOAT127.50–255
white_levelFLOAT255.00–255
channelCOMBO3 options: red, green, blue
shrink_growINT0-128–128
invertINT00–1
blur_radiusFLOAT5.00–1024
maskoptMASK

Outputs (3)

NameTypeDescription
mask_imageIMAGE
maskMASK
mask mappingMASK_MAPPING