Nodes/ComfyUI-GGUF-Loader/TripoSG Prepare Image ⚡
ComfyUI Node

TripoSG Prepare Image ⚡

TripoSG's One Right Way to Frame a Photo

By ChrisColeTech·Created 2 months ago·Updated 4 days ago· 24
TripoSG Prepare Image ⚡
  • image
  • rmbg
  • mask
  • image
◄remove_backgroundtrue►
◄padding_ratio0.10►
◄backgroundwhite►

TripoSG reconstructs whatever it's looking at. So the most valuable thing you can do before sampling is make sure it's looking at the object and nothing else: no desk, no shadow, no 4:3 letterboxing, no subject jammed against the left edge. This node is the POC's preprocessing, cut out as a node - matte, crop, pad, done.

What it actually does

Six steps, and each one is copied from the reference pipeline rather than invented:

  1. Downscale if the long side exceeds 2000 px.
  2. Work out whether the image has a meaningful alpha. The test is a 20-bin alpha histogram: at least 1% of pixels must land in the lowest bin and at least 1% in the highest. That's a clever way of asking "is this a real cutout or a fully-opaque image with a stray alpha channel?"
  3. If the alpha is meaningful, use it. If not, run RMBG-1.4, then Otsu-threshold the predicted mask and strip small blobs (components under 200 px). That combination is why TripoSG's crop is more forgiving than a raw RMBG matte.
  4. Bounding box at any alpha > 0 - much looser than TRELLIS.2's 0.8 threshold.
  5. Composite the subject onto your chosen background colour (default white), inside the crop.
  6. Centre a square around it and add padding_ratio on every side.

Output is one IMAGE: square, RGB, subject centred, background solid. That goes to the Sampler, and nowhere else.

The inputs you'll touch

  • image - source frame, required.
  • remove_background - default on, exactly as the POC does it. Turning it off treats the whole frame as subject and just squares/pads it, which is correct for an already-isolated render and wrong for a photo.
  • padding_ratio - 0.1 default. Bigger eats resolution, smaller crops tight. TripoSG's shape model likes a little margin; don't set it to 0 because you're trying to be clever.
  • background - white (default), black, gray. White is what the model was trained against. Changing it is the kind of idea that seems harmless and measurably isn't.

Optional rmbg (a CCTECH_TRIPOSG_RMBG from the RMBG Loader) and mask. The mask socket is LoadImage's alpha convention - 1 = transparent - which is the opposite of TRELLIS.2's Prepare Image. If you're feeding it a foreground mask from core's Remove Background, put an InvertMask in front or you'll crop to the background.

The 1 = transparent detail, because it bites

Two nodes in this pack, same-sounding job, opposite mask conventions. TRELLIS.2 / Pixal3D Prepare Image wants 1 = subject. TripoSG Prepare Image wants 1 = transparent. Neither of those is wrong - one reads a foreground mask, the other reads an alpha channel - but it means you cannot copy/paste a mask chain between the two pipelines and assume it works. Worth a sticky note.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/ChrisColeTech/ComfyUI-GGUF-Loader
pip install -r ComfyUI/custom_nodes/ComfyUI-GGUF-Loader/requirements.txt

ComfyUI Manager search "ComfyUI-GGUF-Loader" works too. This node itself has no model weights - it's PIL and numpy - but if you leave remove_background on you need the RMBG Loader wired and a BriaRMBG-1.4 folder in models/triposg/.

The errors, and what they mean

"connect a TripoSG RMBG Loader, or an alpha mask, or turn remove_background off." You asked for background removal, gave it nothing to remove with. Not a crash, a demand for a decision.

"the mask has no meaningful alpha; connect a TripoSG RMBG Loader." You passed an alpha, but it failed the 1%-at-each-end test - almost always because you passed an opaque image's alpha or a foreground mask in the wrong polarity. The node tries the alpha, finds it useless, and needs RMBG to take over.

Batches of different shapes. Crops don't come out the same size, so the node resizes everything to the first item's dimensions and logs a warning. Fine for a quick batch of similar props, mildly lossy for a batch of a phone and a chair. Run those separately.

The one philosophical caveat: this node is opinionated on purpose. TripoSG is a single-image model with a fixed idea of composition, and the whole point here is to hand it exactly the frame it expects. If you find yourself fighting the crop, you're fighting the training distribution.

Category🤖 CCTech/TripoSG

Inputs (6)

NameTypeDefaultDescription
imageIMAGE—
remove_backgroundBOOLEANtrueRun RMBG-1.4 when the image has no meaningful alpha (the POC always does). Off: the whole frame is treated as the subject.
padding_ratioFLOAT0.100–1Border added around the subject's square crop (POC: 0.1).
backgroundCOMBOwhiteFill behind the subject (POC: white).
rmbgoptCCTECH_TRIPOSG_RMBG—
maskoptMASKLoadImage's alpha mask (1 = transparent). Used instead of RMBG when the alpha is meaningful (>=1% fully transparent and >=1% opaque), as the POC does. A foreground mask (1 = subject, e.g. core Remove Background) needs InvertMask first.

Outputs (1)

NameTypeDescription
imageIMAGE—