Align Stylized Frame
Fixing the one thing every Flux restyle gets wrong
- original_image
- stylized_image
- subject_mask
- aligned_image
- difference_map
- alignment_info
- subject_mask
- inpaint_mask
You restyle a video frame with Flux img2img, and the character has drifted three pixels left, shrunk 4%, and rotated a hair. Frame by frame that's nothing. Stacked across a 24fps clip it's the wobble that screams "AI." Align Stylized Frame is the fix: it takes your stylized image, aligns it back onto the original source frame, and - if you want - keeps the stylized subject itself untouched while only the background gets resettled. It's the node that makes AI-styled shots actually composite like plates instead of floating.
The mechanism is worth understanding because it's why this beats eyeballing it in an editor. Global alignment starts with FFT phase-correlation to get a rough translation seed, then refines with Adam optimization on contrast-normalized edge maps - recovering translation, scale, and optionally rotation down to sub-pixel precision. There's an ECC fallback, which is the pack author's way of guaranteeing the output is never worse than the input. Then subject mode kicks in: BiRefNet segments the subject in both images, DWPose shoulder-matching (with centroid/area fallback for non-people) pins the subject's position, and the untouched stylized subject gets pasted back at the corrected spot.
Where people get burned: that pasting leaves gaps at the edges, and the borders need filling. inpaint_method defaults to lama, a ~196MB auto-downloaded big-lama removal model - purpose-built for exactly this, one forward pass, fast. The void option is Netflix VOID diffusion, which is a video model run on a replicated 5-frame clip for stills. It's much slower and in the author's own testing LaMa matched or beat it on single frames, so treat VOID as the future video-batch engine, not today's default. The old sd_inpaint value maps to lama automatically.
The inputs that matter
Only two are required: original_image and stylized_image. Everything else has sane defaults. The ones you'll actually touch:
subject_mode-birefnet(default) is the high-quality path and needs BiRefNet from ComfyUI core.disabledgives you global-only alignment;masklets you feed your own subject mask;autois the cheap fallback.inpaint_method-lamarecommended,noneif you'd rather take theinpaint_maskoutput and run your own inpainting pass downstream.conform_to_original- 0 keeps the stylized look, 1 forces a match to the original. Defaults to 1.max_subject_shift- the guardrail. If the detected subject move exceeds this many pixels, subject correction is skipped, because a segmentation mismatch can fling content across the frame and that's worse than no correction.
Outputs: aligned_image is what you wire onward. difference_map is a 2x-wide side-by-side diagnostic (not a same-size frame - that trips people), alignment_info is a text report, and subject_mask / inpaint_mask are there when you need to drive your own edits.
Install and models
It ships in TrentNodes. Install via ComfyUI Manager (search "Trent Nodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/TrentHunter82/TrentNodes.git
cd TrentNodes && pip install -r requirements.txt
Two downloads happen on first use: BiRefNet (via ComfyUI core, standard model folders) and big-lama (~196MB) which auto-downloads to models/inpaint/big-lama.pt. Note that batches use frame-0 geometry for all frames - fine for a restyled clip, not a substitute for per-frame tracking. If you see gray fill or wobble at edges, raise mask_expand and check that fill_transform_edges stayed on.
Inputs (18)
| Name | Type | Default | Description |
|---|---|---|---|
| original_image | IMAGE | — | |
| stylized_image | IMAGE | — | |
| scale_rangeopt | FLOAT | 0.050.01–0.2 | Maximum scale deviation (0.05 = +/- 5%) |
| translation_rangeopt | INT | 324–128 | Maximum translation in pixels |
| search_precisionopt | COMBO | balanced | Search quality vs speed tradeoff |
| enable_rotationopt | BOOLEAN | true | Estimate small global rotation during alignment |
| max_rotation_degopt | FLOAT | 3.00–15 | Maximum rotation to search (degrees) |
| allow_anisotropic_scaleopt | BOOLEAN | false | Separate X/Y scale - fixes aspect-ratio drift, slight risk of absorbing content differences |
| visualization_modeopt | COMBO | overlay | Visualization type for difference map output. score_map shows the alignment residual before/after. |
| subject_modeopt | COMBO | birefnet | disabled: global only | auto: simple detection | birefnet: high-quality AI | mask: use provided |
| subject_maskopt | MASK | Optional mask for subject (for mask mode) | |
| conform_to_originalopt | FLOAT | 1.00–1 | Conform stylized to original (0=keep stylized, 1=match original) |
| max_subject_shiftopt | INT | 1500–2048 | Skip subject correction when the detected move exceeds this many pixels - guards against segmentation mismatch flinging content across the frame (0 = no limit) |
| fill_transform_edgesopt | BOOLEAN | true | Inpaint edges when scaling/repositioning creates gaps |
| inpaint_methodopt | COMBO | lama | none: output mask for external inpaint | lama: fast removal model (recommended) | void: Netflix VOID diffusion (slow, experimental on stills) | clone_stamp: texture | blur: fast fallback |
| mask_expandopt | INT | 100–50 | Pixels to expand mask before inpainting |
| inpaint_stepsopt | INT | 205–50 | Diffusion steps per pass (void method only) |
| inpaint_denoiseopt | FLOAT | 0.900.5–1 | Unused (kept for old workflow compatibility) |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| aligned_image | IMAGE | — |
| difference_map | IMAGE | — |
| alignment_info | STRING | — |
| subject_mask | MASK | — |
| inpaint_mask | MASK | — |