TrimBG Advanced
The 'cut the empty canvas' step your cutout workflow was missing
- images
- mask
- image
Background removal is the most commoditized operation in the whole ecosystem - BiRefNet's the default, it's even in ComfyUI core now, and it gets you a clean subject mask in under a second. But a removed background leaves you with a full-size canvas and the subject floating in a sea of nothing. TrimBG Advanced (from comfyui-missed-tool) is the cleanup step everyone forgets: it crops the canvas down to your subject's bounding box, so a 1024×1024 cutout becomes just the object, tight.
It's the "Advanced" sibling of the pack's plain TrimBG. The simple version takes an image and auto-crops; this one takes a mask too, plus padding, an alpha threshold, and an optional background fill. It also handles a whole batch, which is the difference between doing one image and doing a hundred.
How it works
Give it an image and a mask, and it composites the subject onto a transparent background, finds the alpha's bounding box, and crops to it. The four knobs are where the control lives:
- mask - your cutout mask (from BiRefNet, a segmentation node, or this pack's Load Image Alpha). If you leave it disconnected, it falls back to using the image's luminance as alpha - handy, but don't expect magic.
- padding - expand (positive) or shrink (negative, down to −1000) the crop around the subject. Negative padding is how you shave the mask's sloppy halo off the edges.
- alpha_thresold - spelled exactly that way in the code, a classic author typo. Any pixel with alpha below this value (0–255) is zeroed out before the bounding box is computed. Raise it to cut wispy, half-transparent edges out of the crop.
- fill_rbg - a hex background color (e.g.
#ffffff) to flood into the remaining transparent pixels, so you get a solid-background image instead of RGBA.
The gotchas that will actually bite
fill_rbgneeds the#. The code only applies the fill when the string is longer than 6 characters -#ffffffworks, butffffffsilently does nothing. Easy to miss; type the hash.- It crops, it doesn't change the content. Semi-transparent areas inside the subject (glass, hair, smoke) that survive the threshold are kept - the fill only touches fully transparent pixels. If you need fractional-alpha handling, that's a matting model's job, not a crop node's.
- Batch pairing. When images come in as a batch, the node pairs each with a mask in order. If your masks come from a node that emits them one at a time instead of as a batch, you'll get mismatched crops - feed both as batches.
Where it fits in a real workflow
The pack author's own recommendation: use the Inspire Pack's Load Image List From Dir to read a folder as a list, BiRefNet (ComfyUI_BiRefNet_ll is the one they name) to build masks, then this to trim. That's a batch pipeline that goes folder → subject cutouts → compositing, and TrimBG Advanced is the node that makes the output presentable instead of a full-canvas float.
Install
Standard for the pack - ComfyUI Manager, search comfyui-missed-tool, or:
cd ComfyUI/custom_nodes
git clone https://github.com/ifmylove2011/comfyui-missed-tool.git
Restart and it's under missed-tool as "TrimBG Advanced". No extra Python dependencies (the pack runs on torch/PIL, already in ComfyUI) - just remember you'll need a segmentation model or mask source upstream to actually use the mask input.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| mask | MASK | — | |
| padding | INT | 0-1000–1000 | — |
| alpha_thresold | INT | 00–255 | — |
| fill_rbg | STRING | rbg value, such as #ffffff |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |