Nodes/ComfyUI-QG-tools/Remove BG by Mask
ComfyUI Node

Remove BG by Mask

Cut out a subject using a mask: keep the pixels inside the mask and make everything else transparent. Optionally fill enclosed holes, crop to the subject bounding box with an adjustable margin, and add an outline. Returns an RGBA image, an RGB image composited over the stroke colour, and the mask actually used. A batch shares one crop box so every frame has the same size.

By live1617·Created about a month ago·Updated a day ago· 4
Remove BG by Mask
  • image
  • mask
  • rgba
  • rgb
  • mask
◄fill_holestrue►
◄crop_to_masktrue►
◄crop_factor1.2►
◄stroke_width0►
◄stroke_color#364254►
CategoryQG-tools/Mask

Inputs (7)

NameTypeDefaultDescription
imageIMAGESource image; all frames in a batch share one crop box so the output stays stackable.
maskMASKMask: values above 127 are kept, the rest is cut away. Resized to the image if sizes differ; the last mask is reused when the batch has fewer masks than images.
fill_holesBOOLEANtrueFill enclosed holes surrounded by foreground (e.g. a ring made by an arm). Only interior gaps are filled; the outside background is untouched.
crop_to_maskBOOLEANtrueCrop the empty border using the foreground bounding box, keeping just the subject area. Turn off to keep the original canvas.
crop_factorFLOAT1.21–2How far to expand the crop box. 1.0 hugs the subject, 1.2 leaves some margin; larger values leave more empty space.
stroke_widthINT00–512Width in pixels of the outline drawn outside the foreground edge; 0 disables it.
stroke_colorSTRING#364254Outline colour, also used as the backdrop of the RGB output. Accepts #RRGGBB / #RGB / RRGGBB; invalid values fall back to the default instead of erroring.

Outputs (3)

NameTypeDescription
rgbaIMAGERGBA cutout with a transparent background.
rgbIMAGEOpaque RGB version: transparent areas are filled with the stroke colour.
maskMASKThe single-channel mask after hole filling and cropping.