Nodes/ComfyUI-ZhiHui/🎨 智绘_智能抠图
ComfyUI Node

🎨 智绘_智能抠图

The rembg cutout node with fourteen models and a proper mask output

By zhuyungen·Created 8 months ago·Updated 4 months ago· 0
🎨 智绘_智能抠图
  • images
  • 背景颜色
  • 图像
  • 遮罩
  • 遮罩图像
◄modelU2-Net 通用标准 (推荐)►
◄灵敏度1.00►
◄处理分辨率1024►
◄遮罩模糊0►
◄遮罩偏移0►
◄反转输出false►
◄精细前景优化false►
◄背景类型透明度►
◄启用Alpha Mattingfalse►
◄Alpha前景阈值240►
◄Alpha背景阈值10►
◄Alpha腐蚀大小10►
◄形态学后处理false►

Background removal is the most commoditized operation in this ecosystem and still nobody's solved hair - but if you want a single node with every serious option behind one dropdown, ZH_BackgroundRemover (🎨 智绘_智能抠图) is a good candidate. It wraps the rembg library with a fourteen-model picker, hands you a real MASK socket (not just an alpha-embedded image), and throws in the quality controls - resolution, matting, blur, offset - that separate a usable cutout from a jagged mess. If you've used rembg in A1111 or ComfyUI-RMBG, you know exactly what this is; this is that, packaged for the 智绘灵箱 pack.

How it works

Under the hood it's rembg - the same MIT-licensed library that's been doing this since 2020 - driving an ONNX model you point it at. The model dropdown maps to the standard rembg roster: u2net and u2netp (the general/speed pair), u2net_human_seg and u2net_cloth_seg (people and garments), silueta, IS-Net general and anime, a quantized SAM, and five BiRefNet weights (general, lite, portrait, DIS, HRSOD, COD). That last family is the one to care about: BiRefNet is the current default recommendation in this space, and it's the model that finally survives flyaway hair reasonably well.

One implementation detail matters: the node does not auto-download anything. It sets rembg's model folder to ComfyUI/models/RMBG/ and scans there (plus ~/.u2net) for .onnx files. If the model isn't on disk it raises a clear error telling you to put it in ComfyUI/models/RMBG/<model>/. So the first-time setup is a manual download - a u2net is ~170MB, BiRefNet around that too - then drop the .onnx file in and it just works, cached in memory across runs.

The inputs that matter

  • model - the one that decides quality. Start with BiRefNet 通用高精度 (RMBG推荐) for hair and tricky edges; fall back to U2-Net 通用标准 if you want the fast classic path.
  • 处理分辨率 (processing resolution) - default 1024, up to 2048. Higher is finer but slower. Feed it roughly your image's native size; BiRefNet specifically likes 1024–2048.
  • 启用Alpha Matting - the optional hair-saver. It's off by default; flip it on for flyaway hair and watch the edge improve dramatically at the cost of speed. Pair it with the Alpha前景阈值/Alpha背景阈值 (240/10 defaults) and Alpha腐蚀大小 (10) controls if the edges look rough.
  • 遮罩模糊 (mask blur) and 遮罩偏移 (mask offset) for softening or expanding/shrinking the mask - handy for composite cleanup.
  • 反转输出 to swap foreground/background, and 背景类型 to output transparency or a solid 背景颜色 instead.

Outputs are the three you actually want: 图像 (IMAGE) with the background removed, 遮罩 (MASK) - the raw mask for feeding inpaint or composite nodes - and 遮罩图像 (IMAGE), the mask rendered as a viewable image. It processes whole batches, which makes it viable for folder-level cleanup.

Install

Install the pack, not the node:

cd ComfyUI/custom_nodes
git clone https://github.com/zhuyungen/ComfyUI-ZhiHui.git

Then pip install -r requirements.txt (the pack needs rembg and onnxruntime - the README only lists four bare deps but the real requirements file is heavier), restart ComfyUI, and put your .onnx models in ComfyUI/models/RMBG/. ComfyUI Manager search "智绘灵箱" / "ComfyUI-ZhiHui" works too. Note: rembg ships with its own session/download helper, but this node deliberately does not trigger it - manual placement is the documented path.

Where people get burned

  • "Model not downloaded" on first run. Expected. The error message is explicit: put the .onnx in ComfyUI/models/RMBG/<model>/.
  • Hair still looks bad? You picked u2net. That model's edge quality has been "acceptable, not exceptional" since 2020. Switch to BiRefNet before you touch any other slider.
  • The 灵敏度 (sensitivity) slider isn't a magic wand - it modulates detection, not edge quality. If the whole subject is being cut off or the background is leaking in, adjust resolution and matting first.
  • GPU acceleration is optional. The requirements file has onnxruntime CPU by default; if batch removal is slow, swap in onnxruntime-gpu per the pack's own instructions.

Honest verdict: if you already run ComfyUI-RMBG or BiRefNet natively you don't need this. But if you're in this pack anyway, this is a genuinely complete cutout node - fourteen models, real mask output, matting controls - and the RMBG/BiRefNet recommendation matches where the community actually landed.

Category智绘灵箱/图片

Inputs (15)

NameTypeDefaultDescription
imagesIMAGE输入需要抠图的图片
modelCOMBOU2-Net 通用标准 (推荐)选择抠图模型
灵敏度FLOAT1.000–1灵敏度控制(值越高检测越灵敏)
处理分辨率INT1024256–2048处理分辨率(越高越精细但越慢)
遮罩模糊INT00–64遮罩边缘模糊程度
遮罩偏移INT0-64–64遮罩边界偏移(正值扩展,负值收缩)
反转输出BOOLEANfalse反转遮罩和图像
精细前景优化BOOLEANfalse使用快速前景颜色估算优化透明背景
背景类型COMBO透明度选择输出背景类型
背景颜色optCOLORCODE#222222背景颜色(仅在背景类型为颜色时生效)
启用Alpha MattingoptBOOLEANfalse启用Alpha Matting精细边缘优化(头发丝、毛发等细节更清晰,但速度较慢)
Alpha前景阈值optINT2400–255前景阈值(0-255),值越高对前景判断越严格
Alpha背景阈值optINT100–255背景阈值(0-255),值越低对背景判断越严格
Alpha腐蚀大小optINT100–50腐蚀核大小,用于平滑边缘(值越大边缘越平滑)
形态学后处理optBOOLEANfalse启用形态学后处理(自动去除噪点和填充孔洞)

Outputs (3)

NameTypeDescription
图像IMAGE—
遮罩MASK—
遮罩图像IMAGE—