Nodes/ComfyUI-RMBG/Finegrain Box Segmenter (RMBG)
ComfyUI Node Runs on cloud

Finegrain Box Segmenter (RMBG)

Point at the thing you want, get only that thing

By 1038lab·Created 2 years ago·Updated 22 days ago· 2,226
Finegrain Box Segmenter (RMBG)
  • image
  • bboxes
  • background_color
  • IMAGE
  • MASK
  • MASK_IMAGE
◄box_coordinates►
◄margin0.15►
◄mask_blur0►
◄mask_offset0►
◄invert_outputfalse►
◄unload_modelfalse►
◄backgroundAlpha►

A normal background remover makes a decision for you: this is the subject, everything else goes. That's the wrong question in about half of real work. You don't want the foreground of a product shot with three items in it - you want the second one. You don't want the person cut out, you want the jacket.

Finegrain Box Segmenter is the pack's box-promptable matting node. You tell it where, it works out exactly which pixels. It's the difference between "remove background" and "extract this".

The mechanism

It's a 1024px salient-object matting model - Swin-B, in the MVANet line - loaded through the refiners library as a BoxSegmenter. Box-prompted segmentation is an old idea with a good reputation: give the model a crop-sized hint and the ambiguity collapses, because it no longer has to decide which object is the interesting one. It only has to decide where that object's boundary runs. Which is the hard half, and where a dedicated matting model earns its keep over a plain detector - detectors give you rectangles, and rectangles cut through shoulders.

If you hand it no boxes at all, it falls back to segmenting the default subject of the whole image. That's a feature and also a trap; more on that below.

Wiring it

bboxes is the input that makes this worth installing. It's a BBOX type, and the intended feed is the pack's own detection nodes - Florence-2 or YOLO - so the graph becomes: detect, then matte, with no coordinates typed by a human. That's the workflow this node exists for, and it scales to a folder of images without you touching it.

box_coordinates is the manual path: a string like 120, 80, 640, 720. The node is forgiving about units - if every value is ≤ 1.0 it treats them as normalized fractions of the image, otherwise as pixels, and it clamps whatever you give it to the image bounds. Note the tolerated case: if the string doesn't parse, the node silently falls through to "no boxes" and segments the whole image's main subject instead. You get a plausible-looking result that isn't the one you asked for. If your output looks like a generic cutout, check that string first.

margin (default 0.15) pads each box before the model sees it. This is genuinely useful - too tight a crop and the model has no context for where the edge should go, so you get clipped hair or a chopped-off ear. 0.1–0.2 is the sane range. Above that you're feeding it the neighbours.

The rest is edge cleanup, identical to the rest of the pack: mask_blur and mask_offset for softening and growing/shrinking, invert_output, unload_model, and background / background_color for choosing between a transparent cutout and a solid backdrop.

Outputs

IMAGE is the cutout - RGBA in Alpha mode, RGB composited on your colour otherwise. MASK is the matte, ready for inpainting or compositing. MASK_IMAGE is that mask rendered as a grey image, for previews only; it will not satisfy a MASK socket.

One structural thing to know: multiple boxes produce one mask, not one per box. The node runs the segmenter on each box and unions the results with a pixel-wise max. Two boxes on two objects gives you both objects in a single silhouette. If you needed them separate, run two nodes - or use the YOLO node's MASK_LIST, which is the output designed for that.

Install

ComfyUI Manager → search ComfyUI-RMBG, or:

cd ComfyUI/custom_nodes
git clone https://github.com/1038lab/ComfyUI-RMBG
./ComfyUI/python_embeded/python -m pip install -r ComfyUI-RMBG/requirements.txt

This node needs refiners, which is in requirements.txt as of v3.3.0 but not in the README's dependency list - if you see RuntimeError: The 'refiners' library is required for Finegrain Box Segmenter, your install predates the node and you just need to rerun the pip command.

The weights auto-download on first run from 1038lab/finegrain-box-segmenter into ComfyUI/models/RMBG/finegrain-box-segmenter/. For an offline machine, drop finegrain-box-segmenter.safetensors there yourself.

Where it goes wrong

Output is the whole subject, not your object. Either box_coordinates didn't parse, or the bboxes link is empty because the detector upstream found nothing. The detector's own confidence threshold is the usual culprit - it's a separate node with a separate setting, and it fails quietly.

Boxes come back offset. Coordinate-space mismatch: boxes produced from a resized or cropped image, applied to the original. The normalized-fraction support saves you here - ask the detector for normalized output if it can give it.

Edge is clipped on one side. Raise margin. The box is doing the work here, and a box that hugs the object is a box that tells the model to stop at the box.

Licence note, if you're shipping. The pack is GPL-3.0. Finegrain's own weights are the thing to check separately for commercial use - the model card, not the node repo, is the source of truth.

Category🧪AILab/🧽RMBG

Inputs (10)

NameTypeDefaultDescription
imageIMAGEInput image batch to segment with high definition 1024px quality.
bboxesoptBBOXBounding box(es) from Florence-2 or YOLO detection nodes.
box_coordinatesoptSTRINGManual bounding box as 'x1, y1, x2, y2' in pixel or normalized [0..1] coordinates.
marginoptFLOAT0.150–0.5Safety padding margin around bounding boxes.
mask_bluroptINT00–64Blur mask edges (0 to disable).
mask_offsetoptINT0-64–64Expand (positive) or shrink (negative) mask edges in pixels.
invert_outputoptBOOLEANfalseInvert the output mask.
unload_modeloptBOOLEANfalseUnload model from VRAM immediately after execution.
backgroundoptCOMBOAlphaBackground type: Alpha (transparent) or Color (custom solid background).
background_coloroptCOLORCODE#222222Hex color code for background when Color mode is selected.

Outputs (3)

NameTypeDescription
IMAGEIMAGE—
MASKMASK—
MASK_IMAGEIMAGE—