Auto GrabCut Background Remover
YOLO finds the subject, GrabCut carves it out
- image
- initial_mask
- image
- mask
- bbox_coords
- confidence
- metrics
- bbox_tensor
This is the one node in the pack that actually runs a neural network, and it's the one that feels like magic on real photos. Instead of guessing what "background" means by color, Auto GrabCut first runs YOLOv8 object detection to find the subject (the yolov8n weights ship right in the repo), then hands the detected bounding box to OpenCV's GrabCut. GrabCut segments the object by iteratively modeling foreground and background color distributions, so the boundary snaps to actual object edges rather than a color flood-fill. A second pass refines those edges and optionally feathers them.
That two-stage design is the whole point. The flagship's color clustering has to guess; here YOLO already told the node where the person is, and GrabCut only has to separate person from surroundings inside that box. On a clean subject it beats the color approach, and it's the pack's answer for photos rather than sprites.
The input that matters most
object_class - auto, person, product, vehicle, animal, furniture, electronics. Honest caveat from the source: those presets map to single YOLO classes. "product" literally means "bottle," "animal" means "dog," "vehicle" means "car," "electronics" means "laptop." It's a pragmatic shortcut, not a taxonomy, so a photo of a couch under "furniture" (→ chair) can miss. auto just takes the highest-confidence detection of any class, which is the sensible default.
The rest of the knobs are about the detection and the cut: confidence_threshold (0.3-0.9) for how sure YOLO must be, grabcut_iterations (1-10), margin_pixels around the box, edge_refinement (0-1), and edge_blur_amount (0-10) for Gaussian-feathered mask edges - 0 skips blur entirely for sharp cuts. bbox_safety_margin and min_bbox_size police over-cropping; fallback_margin_percent is what happens when YOLO finds nothing (a margin-based box instead of a crash). output_size goes ORIGINAL, 512, 1024, 2048, or custom with custom_width/custom_height. output_format is RGBA or a plain MASK, invert_mask flips it, and there's an optional initial_mask to skip detection when you already have a rough mask.
Outputs - two useful, four for the curious
image and mask are the normal ones. The other four - bbox_coords (STRING), confidence (FLOAT), metrics (STRING), and bbox_tensor (a custom BBOX_TENSOR type) - are inspection streams. confidence is genuinely handy: it tells you how sure YOLO was, so a weak cut on a low-confidence frame is explainable. The custom tensor type won't plug into stock nodes, so you'll mostly ignore those four.
The catch
This node needs ultralytics, and if it's missing, the entire GrabCut section of the pack is disabled at load with a console warning. It's in requirements.txt, so a normal install gets it:
cd ComfyUI/custom_nodes
git clone https://github.com/Limbicnation/ComfyUI-TransparencyBackgroundRemover.git
cd ComfyUI-TransparencyBackgroundRemover
pip install -r requirements.txt
YOLO init is lazy and cached, so the first run pays a model-load tax and later ones don't. And since the neural path is really about subject location, not matting - same limits as every segmentation approach: hair and semi-transparent material still come out imperfectly. That's when you'd move up to a dedicated matting model.
Inputs (20)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| object_class | COMBO | 7 options: auto, person, product, vehicle, animal, furniture, +1 | |
| confidence_threshold | FLOAT | 0.500.3–0.9 | Minimum confidence for object detection |
| grabcut_iterations | INT | 51–10 | Number of GrabCut algorithm iterations |
| margin_pixels | INT | 200–50 | Pixel margin around detected object |
| edge_refinement | FLOAT | 0.70–1 | Edge refinement strength (0=none, 1=maximum) |
| edge_blur_amount | FLOAT | 0.00–10 | Amount of Gaussian blur to apply to mask edges (0=none, 10=maximum) |
| bbox_safety_margin | INT | 300–100 | Extra pixels beyond detected bounding box for safety |
| min_bbox_size | INT | 6432–256 | Minimum bounding box dimensions to prevent over-cropping |
| fallback_margin_percent | FLOAT | 0.200.1–0.5 | Margin percentage for fallback bbox when no object detected |
| binary_threshold | INT | 200128–250 | Threshold for binary mask conversion |
| output_size | COMBO | ORIGINAL | Target output size for the processed image and mask |
| scaling_method | COMBO | NEAREST | Interpolation method for scaling: NEAREST (pixel-perfect), BILINEAR (smooth), BICUBIC (high-quality), LANCZOS (best quality) |
| auto_adjust | BOOLEAN | false | Automatically adjust parameters based on image content analysis |
| initial_maskopt | MASK | — | |
| output_formatopt | COMBO | RGBA | Output format: RGBA with alpha channel or binary MASK (0=background, 255=foreground) |
| invert_maskopt | BOOLEAN | false | Invert the output alpha/mask (swap foreground and background) |
| custom_widthopt | INT | 51264–4096 | Custom width (used when output_size is 'custom') |
| custom_heightopt | INT | 51264–4096 | Custom height (used when output_size is 'custom') |
| edge_detection_modeopt | COMBO | AUTO | Edge detection optimization: AUTO (detect content type), PIXEL_ART (sharp edges), PHOTOGRAPHIC (smooth edges) |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| bbox_coords | STRING | — |
| confidence | FLOAT | — |
| metrics | STRING | — |
| bbox_tensor | BBOX_TENSOR | — |