Nodes/ComfyUI-RMBG/Crop To Object (RMBG) 🖼️🎭
ComfyUI Node Runs on cloud

Crop To Object (RMBG) 🖼️🎭

Crop To Object (RMBG)

By 1038lab·Created 2 years ago·Updated 8 days ago· 2,051
Crop To Object (RMBG) 🖼️🎭
  • image
  • mask
  • IMAGE
  • MASK
padding0

Crop To Object does the obvious-once-you-need-it thing: it takes an image and a mask and crops the image tight to whatever the mask covers. Cut a subject out with RMBG, feed the result here, and you get the subject cropped to its bounding box - no more giant transparent margins around a small figure. It's the cleanup step after background removal that turns "a person floating in a 4000px empty canvas" into "a person, framed."

The mechanism is simple geometry, no model involved. It reads the mask, finds the tightest rectangle that contains all the non-empty pixels, and crops both the image and the mask to that box. That's it. The value is in not doing it by hand - after a segmentation or removal step, the useful content is often a fraction of the canvas, and cropping to it saves memory downstream, makes the subject the right size for compositing, and gives you a clean asset instead of one swimming in transparency.

The inputs are minimal. image and mask are both optional ports (you'll normally wire both, straight from a background remover or segment node - the image is what gets cropped, the mask defines where). padding (0–256, default 0) adds a margin of breathing room around the bounding box, in pixels - bump it up if a zero-padding crop feels claustrophobically tight against the subject, or if you want a little context around the object. Outputs are IMAGE (the cropped picture) and MASK (the mask cropped to match, so it stays aligned with the image for any further masking).

Install rides with the pack: "Comfyui-RMBG" in ComfyUI Manager, or cd ComfyUI/custom_nodes && git clone https://github.com/1038lab/ComfyUI-RMBG, then pip install -r requirements.txt and restart. Nothing to download - it's pure logic.

Practical notes. The crop is only as good as the mask, so a noisy mask with stray specks far from the subject will blow the bounding box out to include them - clean the mask first (a mask_offset shrink or a blur on the upstream node) if the crop comes back weirdly large. That's the one gotcha: a single white pixel in the corner and your "tight crop" is the whole image again. The padding control is worth a few pixels almost always - a dead-tight crop can clip anti-aliased edge pixels and hair, and a small pad keeps them. And because it outputs the cropped mask too, you can chain it: crop to object, then hand the aligned mask to an inpaint or a matting node working on the smaller, cheaper canvas.

Where it fits: this is a finishing/utility node, the natural partner to any cutout in this pack. The workflow is almost always remover-or-segmenter → Crop To Object → whatever's next. It shines in product-shot and asset pipelines where you're generating clean, tightly-framed cutouts in bulk. Notably it has the best click-through and search position of any node in this pack - small as it is, people clearly go looking for exactly this, because "crop to the subject" is a need you feel the instant you've removed a background and stared at all that empty space.

Category🧪AILab/🖼️IMAGE

Inputs (3)

NameTypeDefaultDescription
imageoptIMAGE
maskoptMASK
paddingoptINT00–256

Outputs (2)

NameTypeDescription
IMAGEIMAGE
MASKMASK