Nodes/lf-nodes/Create Mask
ComfyUI Node

Create Mask

Make a mask by typing what you want to select

By lucafoscili·Created 2 years ago·Updated 6 days ago· 35
Create Mask
  • processor
  • model
  • image
  • clip
  • ui_widget
  • mask
  • mask_list
  • image
  • image_list
prompt
threshold_modeotsu
threshold0.50
relative_scale0.50

This is the node that turns a sentence into a mask. Type person, red dress, mountain into LF_CreateMask and it returns a MASK selecting exactly that thing - no manual painting, no bounding boxes, no SAM click-points. It runs CLIPSeg, the zero-shot text-to-segmentation model, which is the same "targeted masking" family as GroundingDINO+SAM but with the box step removed. It's not as precise as the full chain, and it knows it - but for "mask the subject" workflows it's one node instead of three.

The name is doing honest work here: unlike the LF_RegionMask node (which carves masks out of detected bounding boxes), this one creates a mask from scratch, driven by your text.

How it works

Required inputs: processor and model (both from the LF_LoadCLIPSegModel loader in this pack), image, your prompt, and threshold_mode. The threshold mode is where the real choices live:

  • otsu (default) - auto-computes the binarization cutoff from the probability map. Start here; it's the "make it work" setting.
  • fixed - uses your exact threshold value (0–1, default 0.5). Lower it to include more pixels, raise it to shrink the selection.
  • relative - uses relative_scale (default 0.5) as a fraction of the peak probability. A middle ground when a fixed threshold keeps misfiring on images with different contrast.

The optional clip input is the one trap worth flagging: you can feed a standard Stable-Diffusion CLIP to help with text understanding, but the tooltip is blunt that its embeddings won't match the CLIPSeg head, so mask accuracy degrades unless you've fine-tuned or inserted an adapter. In other words: leave it empty unless you know exactly why you're adding it.

Outputs

mask / mask_list - the binarized mask tensor(s), ready for inpainting, compositing, or feeding a RegionalPrompt-style setup. It also passes through image / image_list, so you can keep the pipeline unbroken without a duplicate load. The ui_widget compare preview shows the mask over the source so you can sanity-check before it goes downstream.

Installing it

lf-nodes installs as one pack:

cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/lf-nodes

then restart ComfyUI (or ComfyUI Manager → "LF Nodes"). You need transformers (in the pack's requirements) and the small CLIPSeg weights from the loader node.

Common issues

  • Mask too fat or too skinny - thresholding problem, not the model. Cycle otsufixed with a lower thresholdrelative, in that order.
  • Nothing selected at all - make sure the model actually loaded (check the loader's log) and that your prompt describes something visually distinct in the frame.
  • The clip input making things worse - that's the expected behavior, not a bug. Remove it and stick with the CLIPSeg's own text encoder.
Category✨ LF Nodes/Image

Inputs (9)

NameTypeDefaultDescription
processorCLIP_PROCESSORCLIPSegProcessor from LF_LoadHFModel (segmentation model).
modelCLIP_MODELCLIPSegForImageSegmentation from LF_LoadHFModel (segmentation model).
imageIMAGEImage tensor to segment.
promptSTRINGText prompt for mask.
threshold_modeCOMBOotsuThresholding mode: 'fixed' uses the exact threshold value; 'relative' scales threshold by max probability; 'otsu' auto-computes.
clipoptCLIPOptional Stable-Diffusion CLIP model: ⚠️ Embeddings from this CLIP will not perfectly match the segmentation head—expect degraded mask accuracy unless you fine-tune or insert an adapter.
thresholdoptFLOAT0.500–1Binarization threshold on mask probabilities (0→1). Lower to include more pixels.
relative_scaleoptFLOAT0.500–1Fraction of peak probability to use when in 'relative' mode.
ui_widgetoptLF_COMPARE[object Object]

Outputs (4)

NameTypeDescription
maskMASKGenerated mask tensor.
mask_listMASKList of generated mask tensors.
imageIMAGEOriginal image tensor.
image_listIMAGEList of original image tensors.