Create Mask
Make a mask by typing what you want to select
- processor
- model
- image
- clip
- ui_widget
- mask
- mask_list
- image
- image_list
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 exactthresholdvalue (0–1, default 0.5). Lower it to include more pixels, raise it to shrink the selection.relative- usesrelative_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
otsu→fixedwith a lowerthreshold→relative, 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
clipinput making things worse - that's the expected behavior, not a bug. Remove it and stick with the CLIPSeg's own text encoder.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| processor | CLIP_PROCESSOR | CLIPSegProcessor from LF_LoadHFModel (segmentation model). | |
| model | CLIP_MODEL | CLIPSegForImageSegmentation from LF_LoadHFModel (segmentation model). | |
| image | IMAGE | Image tensor to segment. | |
| prompt | STRING | Text prompt for mask. | |
| threshold_mode | COMBO | otsu | Thresholding mode: 'fixed' uses the exact threshold value; 'relative' scales threshold by max probability; 'otsu' auto-computes. |
| clipopt | CLIP | Optional 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. | |
| thresholdopt | FLOAT | 0.500–1 | Binarization threshold on mask probabilities (0→1). Lower to include more pixels. |
| relative_scaleopt | FLOAT | 0.500–1 | Fraction of peak probability to use when in 'relative' mode. |
| ui_widgetopt | LF_COMPARE | [object Object] | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| mask | MASK | Generated mask tensor. |
| mask_list | MASK | List of generated mask tensors. |
| image | IMAGE | Original image tensor. |
| image_list | IMAGE | List of original image tensors. |