Nodes/NH-Nodes/Garment Segment (NH)
ComfyUI Node

Garment Segment (NH)

Cut the shirt out with a SegFormer mask, no hand-painting

By jetthuangai·Created 5 months ago·Updated 21 days ago· 6
Garment Segment (NH)
  • image
  • mask
  • cutout_rgba
  • mask_image
partupper_garment
attach_partstrue
mask_expand0
mask_blur0
fill_holesfalse
devicecuda

Some masks you paint by hand. A garment mask - following the exact edge of a jacket, sleeves, collar, zipper - is not one of them. Garment Segment (NH) is the automation: it runs a SegFormer model trained on fashion images, reads which pixels are clothing, and returns a clean mask of the part you asked for. It's the front half of a virtual-try-on pipeline, and it's also just the fastest way to cut a shirt out of a photo for compositing.

The output is a per-pixel mask, not a box - so the seam follows the garment, which is exactly what makes the later inpaint or composite look natural.

How it works

Pick the part you want from the part dropdown:

  • upper_garment - tops, jackets, coats, dresses, ties, scarves, collars, sleeves. Important: dresses and jumpsuits count as upper_garment here. This is the one most people use for VTON.
  • lower_garment - pants, shorts, skirts, belts, tights. Shoes deliberately excluded.
  • footwear - shoes and socks.
  • headwear - hats, headbands, hair accessories.

Under the hood it runs a Fashionpedia-trained SegFormer and unions the class IDs for your chosen part. The attach_parts toggle (default on) merges pockets, zippers, bows and ruffles - but only when they actually touch the selected garment, so a stray bow sitting on the table doesn't get sucked into the mask. That's a nice piece of judgment for a default.

Three refinement controls cover the fiddly bits:

  • mask_expand (−64 to +64) - grow or shrink the mask by N pixels. Shrink a hair to avoid bleeding, or grow a hair to cover a seam.
  • mask_blur - feather the edge by N pixels. This is the single most important quality setting: a few pixels of blur kills the hard edge that makes cutouts look pasted-on.
  • fill_holes - default off for garments, on purpose: an arm across the torso would otherwise fill in the gap between torso and arm, destroying the cutout. Leave it off unless your garment genuinely has enclosed holes to fill.

There's also a device selector (cuda/cpu) - leave it on cuda unless you're troubleshooting.

Outputs

  • mask - the MASK tensor itself, ready for inpaint conditioning or a composite.
  • cutout_rgba - the input image with the mask as alpha. The RGB is untouched outside the mask, so you can paste the garment onto another background directly.
  • mask_image - the mask rendered as an RGB preview image, for eyeballing without a mask viewer.

The one thing that's not free: the model

This node downloads a model on first use - a SegFormer fashion weights file, roughly 190 MB, saved to models/NH-Nodes/ (the pack reuses an existing models/face_parsing or models/RMBG/segformer_fashion copy if you have one). The first run will stall for a bit on that download; subsequent runs are local and fast. It's the rare NH node with a real dependency, so don't be surprised when your first queue takes a while.

Installing

cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt

Or install NH-Nodes via ComfyUI Manager and restart. The install itself is standard; the model download is what's heavyweight. If the mask comes out rough, the fix order is: mask_expand to correct coverage, then mask_blur to soften the edge - rarely the other way around.

CategoryNH-Nodes/Vision

Inputs (7)

NameTypeDefaultDescription
imageIMAGE
partCOMBOupper_garment4 options: upper_garment, lower_garment, footwear, headwear
attach_partsBOOLEANtrueMerge pockets, zippers, bows, ruffles... that touch the selected garment.
mask_expandINT0-64–64Grow (+) or shrink (-) the mask by N pixels.
mask_blurINT00–64Feather the mask edge by N pixels.
fill_holesBOOLEANfalseFill enclosed holes. Off for garments by default: an arm across the torso would be filled in.
deviceCOMBOcuda2 options: cuda, cpu

Outputs (3)

NameTypeDescription
maskMASK
cutout_rgbaIMAGE
mask_imageIMAGE