Nodes/MTB Nodes/Image Remove Background Rembg (mtb)
ComfyUI Node Runs on cloud

Image Remove Background Rembg (mtb)

The classic one-click cutout

By melMass·Created 3 years ago·Updated about a month ago· 721
Image Remove Background Rembg (mtb)
  • image
  • bgcolor
  • Image (rgba)
  • Mask
  • Image
alpha_mattingfalse
alpha_matting_foreground_threshold240
alpha_matting_background_threshold10
alpha_matting_erode_size10
post_process_maskfalse

You have an image and you want the subject cut out, background gone, alpha channel where the background used to be. This is the old-reliable way to do that inside ComfyUI. It wraps rembg, the MIT-licensed library that's been the standard "just remove the background" tool since 2020, and by default it runs the u2net model behind it. Fast, tiny, runs on CPU, no fuss.

Here's the honest framing, because background removal is the most crowded corner of the ecosystem right now. rembg's u2net is good, not excellent. It nails solid subjects on contrasting backgrounds and it's been doing that reliably for years. Where it struggles - and this hasn't changed since 2020 - is fine hair, fur, fabric mesh, and anything semi-transparent like a veil or a glass. If your subject has a clean silhouette, this node is all you need and reaching for something heavier buys you nothing. If it has flyaway hair strands, BiRefNet (now in ComfyUI core) or InSPyReNet will give you sharper edges. Pick by which failure you can live with.

How it works

It runs your image through rembg's segmentation model, which predicts a foreground mask, then applies that mask to produce a transparent cutout. Nothing is regenerated - it's masking an existing image.

The inputs that matter

  • image - the picture to cut out.
  • alpha_matting (default off) - the one setting worth experimenting with. Turn it on and rembg runs an extra edge-refinement pass that recovers softer, more natural boundaries, especially on hair. It's slower and occasionally overcooks the edge, so toggle it and compare.
  • bgcolor (default #000000) - the fill color for the composited output. This feeds the third output, where the subject is placed on a solid color instead of transparency.

The three alpha_matting_* numbers (foreground/background thresholds and erode size) only do anything when alpha_matting is on - they tune how aggressively the refinement decides what's definitely foreground versus background. The defaults (240 / 10 / 10) are sensible; leave them until you have a specific edge problem to chase.

Three outputs: Image (rgba) is the transparent cutout you usually want, wire it into a composite or Save Image (as PNG, so the alpha survives). Mask is the raw foreground mask for feeding into other masking nodes. Image is the subject flattened onto bgcolor.

How to install it

ComfyUI Manager: search MTB Nodes (the repo is comfy_mtb), install, restart. Manually: cd ComfyUI/custom_nodes && git clone https://github.com/melMass/comfy_mtb, then restart. MTB is a big grab-bag pack that loads gracefully - if a node's optional dependency is missing it quietly fails to load while the rest work, and it'll point you at http://127.0.0.1:8188/mtb, a dependency panel that installs the missing bits. This node needs the rembg library, so if it doesn't appear, that panel is where you fix it.

Common issues

The big one is the first run: rembg downloads its u2net model (~170MB) to a cache folder the first time you use it, so it needs internet and it'll pause while that happens. If it silently fails, check your connection - and check your antivirus, which has a habit of flagging model files.

Turn alpha_matting on before you decide this node "can't do hair." That's usually the difference between an acceptable cutout and a rough one. And a note that saves a lot of grief: don't background-remove a LoRA training set with this. Stripping backgrounds teaches the LoRA to generate blank backgrounds, and it tends to chew up the edges around your subject. Keep the originals for training. This node is for compositing finished images, not cleaning datasets.

Categorymtb/image

Inputs (7)

NameTypeDefaultDescription
imageIMAGE
alpha_mattingBOOLEANfalse
alpha_matting_foreground_thresholdINT2400–255
alpha_matting_background_thresholdINT100–255
alpha_matting_erode_sizeINT100–255
post_process_maskBOOLEANfalse
bgcolorCOLOR#000000

Outputs (3)

NameTypeDescription
Image (rgba)IMAGE
MaskMASK
ImageIMAGE