Nodes/ComfyUI-RMBG/Mask Extractor (RMBG) 🎭
ComfyUI Node Runs on cloud

Mask Extractor (RMBG) 🎭

Apply a mask to an image with alpha, color, or original background

By 1038lab·Created 2 years ago·Updated 11 days ago· 2,057
Mask Extractor (RMBG) 🎭
  • image
  • background_color
  • mask
  • IMAGE
modeextract_masked_area
backgroundAlpha

You've got an image and a mask; now you want the masked part as an image, with everything else knocked out. Mask Extractor does that final apply - cut the subject out onto a transparent, colored, or original background. It's the step that turns "I have a mask" into "I have a cutout I can use."

In the background-removal pipeline this is the payoff node. Upstream, a model produces a mask of your subject. Here, that mask actually gets applied to the pixels: alpha background for compositing, a solid color for a quick product shot, or the original background left in place when you only want to knock out around a selection. Small node, but it's where the mask becomes a result.

How it works

It takes the image and the mask and combines them according to the mode and background you pick. The mode decides which region survives; the background decides what fills the rest.

The inputs that matter

  • mask (optional MASK) - the selection to apply. This is the mask from your segmentation node.
  • mode - what to do with it: extract_masked_area (keep the masked region, drop the rest - the standard cutout), apply_mask (apply the mask as-is), or invert_mask (keep everything except the masked region). Pick based on whether your mask marks the subject or the background.
  • background - what fills the removed area: Alpha (transparent, for compositing - the usual choice), original (leave the source pixels), or Color.
  • background_color (default #FFFFFF) - the fill color when background is set to Color. White by default; set it to whatever backdrop you want.

One output: IMAGE - the extracted result, ready to composite (if alpha) or save.

How to install it

  • ComfyUI Manager: search Comfyui-RMBG, install, restart.
  • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/1038lab/ComfyUI-RMBG, then pip install -r requirements.txt, and restart.

No model - it just applies a mask you already have.

Common issues

The most common "why is my cutout inverted" moment is a mode mismatch: if your mask marks the background rather than the subject (which happens depending on the model and any invert settings upstream), extract_masked_area keeps the background and drops your subject. Flip to invert_mask, or fix the mask upstream. The other thing to know is that this node is only as good as the mask it's given - a rough, jaggy mask produces a rough, jaggy cutout, and no background setting fixes that. If the edge looks bad, run the mask through Mask Enhancer first (a touch of blur and offset), and for hair or semi-transparent subjects, make sure the mask came from a matting-capable model rather than a hard-edged segmentation one, because Alpha background will expose every flaw the moment you composite onto a different color.

Category🧪AILab/🖼️IMAGE

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
modeCOMBOextract_masked_area3 options: extract_masked_area, apply_mask, invert_mask
backgroundCOMBOAlphaChoose background type
background_colorCOLORCODE#FFFFFFChoose background color (Alpha = transparent)
maskoptMASK

Outputs (1)

NameTypeDescription
IMAGEIMAGE