Make Refs Composite By SAM3
Let SAM3 Cut Your References Out and Arrange Them On a Canvas
- model
- clip
- images
- composite
- mask
Reference sheets are the unglamorous secret of consistent video
Multi-reference video generation - MiniMax H3 reference mode, LTX IC-LoRA guides, Wan SCAIL - loves a reference sheet: all your subject images laid out on one fixed-size canvas so the model sees the whole cast in a single conditioning pass. Building that sheet is normally a manual slog in an image editor: cut out your subject, paste on a canvas, resize, repeat. This node automates it, and its party trick is that it uses SAM3 to cut the subject out for you.
easy makeRefsCompositeBySam3 takes your images and a prompt describing the subject, detects the subject in each image with SAM3, and composites the masked subjects onto a canvas at your target width × height. One composite IMAGE + one MASK out, ready to feed a reference-conditioning pipeline.
How it works
Two modes, chosen by composite_mode:
original(default) - skips SAM3 entirely. Each image is placed on the canvas as-is, and the mask output is a full-white mask (everything included). Cheap, instant, no model needed. Use this when your references are already clean cutouts or when SAM3's segmentation isn't buying you anything.sam3_masked- the real deal. It tokenizes yourpromptwith theclipinput, then runs each image throughSAM3_VideoTrackwith yourdetection_thresholdto find the prompted subject, converts the track to a mask withSAM3_TrackToMask, and composites only the segmented subject onto the canvas. This is where "detect subject in prompt using SAM3" from the README happens.
Either way, the final step is _compose_refs: it arranges the (masked or original) images on a canvas of your width × height against a background of white or black, and produces both the composite image and its mask.
SAM3 matters here because it's the current generation of Meta's segmentation model - the one where a short noun phrase returns a mask for every matching instance without a separate GroundingDINO step. It's the natural fit for "grab the character out of this photo."
The inputs that matter
images- your reference photos.prompt- insam3_maskedmode this is required (empty prompt → hard error). It's the subject description SAM3 looks for, e.g. "a woman with red hair."model+clip- the SAM3 model and text encoder. Only used insam3_maskedmode.width/height(1024) - the target canvas size. This is what your downstream model sees, so set it to the generation resolution.detection_threshold(0.5) - SAM3's confidence bar for accepting a detection. Crank it up if it's grabbing wrong objects; lower it if it misses the subject.background-whiteorblackcanvas behind the composites.composite_mode-originalorsam3_masked, the big switch above.
Outputs: composite (IMAGE) - the arranged canvas; mask (MASK) - where the subjects actually are.
Setup and the traps
Pack install (Manager → ComfyUI-Easy-Media, or git clone + restart). The sam3_masked path imports comfy_extras.nodes_sam3, so you need a ComfyUI build with SAM3 support - if it's missing, the node raises a clear "requires ComfyUI with SAM3_VideoTrack support" error. You'll also need the SAM3 model itself loaded and wired to model.
Where it bites:
- Original mode is the easy win. If you don't have a SAM3 model or your references are already clean, don't install anything -
originalmode needs no model, no clip, and no prompt. The SAM3 machinery only activates when you selectsam3_masked. - Empty prompt in
sam3_maskedmode → immediate error, on purpose. The prompt is what SAM3 searches for; without it there's nothing to detect. - Threshold tuning. At 0.5 the detection can be greedy or shy depending on your subject. If the composite shows half the image or nothing, nudge
detection_thresholdrather than the prompt. - Canvas mismatch. Your
width/heightis the conditioning canvas - setting it to a wildly different aspect than your generation resolution means the downstream model sees scaled references. Match it to the generation.
For anyone building multi-character or multi-reference video workflows, this node is the "arrange the cast" step you didn't know you were missing - and SAM3 makes it genuinely cut-out-clean instead of rough-square crops.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| clip | CLIP | — | |
| images | IMAGE | — | |
| prompt | STRING | — | |
| width | INT | 102464–8096 | — |
| height | INT | 102464–8096 | — |
| detection_threshold | FLOAT | 0.500–1 | — |
| background | COMBO | white | 2 options: white, black |
| composite_mode | COMBO | original | Use original images or SAM3-segmented subjects in the composite. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| composite | IMAGE | — |
| mask | MASK | — |