Segment (Mask Ops)
Build a mask from a color channel, a curve, or a sentence
- image
- mask
- mask_image
- mask
- mask mapping
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 whenseparate_maskis 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_levelof 255 with amid_levelof 127.5 is the neutral starting point, and moving mid is the fastest way to break a mask. - Blobs getting merged - run
separate_maskon and use the mask mapping output; that's exactly what it exists for.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| text | STRING | — | |
| separate_mask | INT | 00–1 | — |
| text_sigma | INT | 300–150 | — |
| use_text | INT | 00–1 | — |
| blend_percentage | FLOAT | 0.000–1 | — |
| black_level | FLOAT | 0.00–255 | — |
| mid_level | FLOAT | 127.50–255 | — |
| white_level | FLOAT | 255.00–255 | — |
| channel | COMBO | 3 options: red, green, blue | |
| shrink_grow | INT | 0-128–128 | — |
| invert | INT | 00–1 | — |
| blur_radius | FLOAT | 5.00–1024 | — |
| maskopt | MASK | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| mask_image | IMAGE | — |
| mask | MASK | — |
| mask mapping | MASK_MAPPING | — |