ComfyUI Node

CLIPSeg

Type a word, get a mask — text-prompted segmentation in ComfyUI

By al-swaiti·Created 2 years ago·Updated 2 months ago· 184
CLIPSeg
  • image
  • mask
  • hard_mask
text
blur7.0
threshold0.40
dilation_factor4

The pitch is almost too simple: you give it an image and a word, and it gives you a mask of that thing. Type "hair" and you get a mask over the hair. Type "shirt", "sky", "the dog" - same deal. No clicking, no drawing, no bounding boxes. That text-driven simplicity is why CLIPSeg has stuck around as a beginner-friendly masking tool even as heavier hitters like SAM showed up; it's one node and a text box, and it lands you a usable mask for inpainting or compositing in seconds.

What it's for and where it sits

Masking is the setup step for a huge chunk of ComfyUI work. You want to inpaint just the face, recolor just the jacket, or cut the subject out to drop onto a new background - all of that needs a mask that says "here, not there." CLIPSeg generates that mask from a text prompt, which puts it in the "intelligent masking" family alongside GroundingDINO-plus-SAM. The difference is weight and precision: SAM plus a text-prompted detector gives you crisper, more reliable object boundaries, but it's more model and more setup. CLIPSeg is a single lightweight model that does text-to-mask in one shot. For "roughly select this region so I can inpaint it," it's plenty. For pixel-perfect hair matting, it isn't - reach for a real matting model there.

How it works

CLIPSeg piggybacks on CLIP's understanding of images and words. It scores how strongly each region of the image matches your text, then turns those scores into a grayscale mask - bright where the model is confident your thing is, dark elsewhere. Because it's a similarity heatmap rather than a hard object detector, the raw mask has soft, fuzzy edges, which is exactly why the node gives you cleanup controls.

The inputs and outputs that matter

  • image - the picture to segment.
  • text - what to find. One concept works best; "red car" is fine, a whole sentence is not.
  • threshold (default 0.4) - the cutoff that turns the fuzzy heatmap into a solid selection. Too high and the mask shrinks or vanishes; too low and it grabs half the image. This is the dial you'll actually tune.
  • blur (default 7) - softens the mask edge for a feathered blend. Good for compositing, less good when you want a crisp cut.
  • dilation_factor (default 4) - grows the mask outward a few pixels, so an inpaint covers a hair past the object edge instead of leaving a seam.

Two outputs: mask (the soft, blurred, feathered version) and hard_mask (a cleaner binary cut). Use mask for blended compositing and inpainting where you want a soft transition; use hard_mask when you need a decisive edge. Wire either into an inpaint node's mask input, a "Set Latent Noise Mask," or a compositing node.

Installing it

Through ComfyUI Manager: search ComfyUI-OllamaGemini, install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/al-swaiti/ComfyUI-OllamaGemini
pip install -r requirements.txt

then restart. CLIPSeg's model weights are small and download automatically on first use - so the first run needs an internet connection and will pause while it fetches them. Note that CLIPSeg ships in several ComfyUI packs; this is the OllamaGemini pack's copy, and it behaves the same as the others.

Where people get burned

The recurring frustration is a mask that's too vague. CLIPSeg is a similarity map, not a precise segmenter, so on cluttered scenes or fine structures (individual hair strands, chain-link, foliage) it smears. When that happens: tighten threshold to sharpen the selection, adjust the text to a simpler, more concrete noun, and lean on hard_mask. If you genuinely need clean edges around hair or a semi-transparent object, CLIPSeg is the wrong tool - a matting model gives you fractional-alpha edges CLIPSeg can't. And a blank mask usually means your threshold is above anything the model matched; drop it and try a plainer word.

Categoryimage

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
textSTRING
bluroptFLOAT7.00–15
thresholdoptFLOAT0.400–1
dilation_factoroptINT40–10

Outputs (2)

NameTypeDescription
maskMASK
hard_maskMASK