🎨 智绘_智能抠图
The rembg cutout node with fourteen models and a proper mask output
- images
- 背景颜色
- 图像
- 遮罩
- 遮罩图像
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 theAlpha前景阈值/Alpha背景阈值(240/10 defaults) andAlpha腐蚀大小(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
.onnxinComfyUI/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
onnxruntimeCPU by default; if batch removal is slow, swap inonnxruntime-gpuper 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.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | 输入需要抠图的图片 | |
| model | COMBO | U2-Net 通用标准 (推荐) | 选择抠图模型 |
| 灵敏度 | FLOAT | 1.000–1 | 灵敏度控制(值越高检测越灵敏) |
| 处理分辨率 | INT | 1024256–2048 | 处理分辨率(越高越精细但越慢) |
| 遮罩模糊 | INT | 00–64 | 遮罩边缘模糊程度 |
| 遮罩偏移 | INT | 0-64–64 | 遮罩边界偏移(正值扩展,负值收缩) |
| 反转输出 | BOOLEAN | false | 反转遮罩和图像 |
| 精细前景优化 | BOOLEAN | false | 使用快速前景颜色估算优化透明背景 |
| 背景类型 | COMBO | 透明度 | 选择输出背景类型 |
| 背景颜色opt | COLORCODE | #222222 | 背景颜色(仅在背景类型为颜色时生效) |
| 启用Alpha Mattingopt | BOOLEAN | false | 启用Alpha Matting精细边缘优化(头发丝、毛发等细节更清晰,但速度较慢) |
| Alpha前景阈值opt | INT | 2400–255 | 前景阈值(0-255),值越高对前景判断越严格 |
| Alpha背景阈值opt | INT | 100–255 | 背景阈值(0-255),值越低对背景判断越严格 |
| Alpha腐蚀大小opt | INT | 100–50 | 腐蚀核大小,用于平滑边缘(值越大边缘越平滑) |
| 形态学后处理opt | BOOLEAN | false | 启用形态学后处理(自动去除噪点和填充孔洞) |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| 图像 | IMAGE | — |
| 遮罩 | MASK | — |
| 遮罩图像 | IMAGE | — |