Image Segmentation
Segmentation in ComfyUI
- image
- mask
Image Segmentation is the node that cuts one specific thing out of a picture. You name a category - "shirt," "background," "person" - and it returns a mask isolating the pixels of that category. That mask is the raw material for background removal, targeted inpainting, or any workflow that needs to separate a subject from its surroundings without a text prompt.
The node wraps Hugging Face's image-segmentation pipeline, defaulting to mattmdjaga/segformer_b2_clothes. That's a SegFormer model fine-tuned specifically for clothing - it understands garments, which is a strong hint about the pack author's intended use case. The pipeline segments the image into labeled regions; the node finds the region whose label matches your category_name and returns it as a mask.
The inputs and output
- image - the
IMAGEtensor to segment. - category_name - the label of the region you want, e.g.
shirtorbackground. This has to match the model's vocabulary - the default model knows clothing categories, so "shirt" works and "chair" doesn't. - model_name - Hub model ID as a string. Any model supporting the image-segmentation task works; its label set defines what
category_namecan be.
The single output, mask, is an IMAGE - a grayscale (or black-and-white) mask of the matching region, normalized 0–1, ready to feed into an inpaint or mask-combine node. Here's the behavior to know: if the category isn't found in the segmentation, the node returns a fully black image rather than erroring.
How to install it
Standard pack install - ComfyUI Manager (search "ComfyUI-Transformers") or:
cd ComfyUI/custom_nodes
git clone https://github.com/kadirnar/ComfyUI-Transformers
Restart ComfyUI. The SegFormer clothes checkpoint is a few hundred MB on first download.
Where people get burned
The default model's scope is the big one: it's a clothing segmenter. It's excellent at garments and will happily mask a "skirt" or "dress," but point it at general scenes and the label mismatch silently returns black masks. Before you debug anything else, check that your category matches the model's domain - or swap in a general-purpose segmentation checkpoint. The silent black-mask failure is the most common "is this broken?" moment, and it's almost always a vocabulary mismatch, not a bug. For the specific job of isolating clothing from an image, this is a sharp little tool; for general segmentation, check the model ID first.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| category_name | STRING | — | |
| model_name | STRING | mattmdjaga/segformer_b2_clothes | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | IMAGE | — |