Nodes/TrentNodes/Align Stylized Frame
ComfyUI Node

Align Stylized Frame

Fixing the one thing every Flux restyle gets wrong

By TrentHunter82·Created 9 months ago·Updated 4 days ago· 36
Align Stylized Frame
  • original_image
  • stylized_image
  • subject_mask
  • aligned_image
  • difference_map
  • alignment_info
  • subject_mask
  • inpaint_mask
scale_range0.05
translation_range32
search_precisionbalanced
enable_rotationtrue
max_rotation_deg3.0
allow_anisotropic_scalefalse
visualization_modeoverlay
subject_modebirefnet
conform_to_original1.0
max_subject_shift150
fill_transform_edgestrue
inpaint_methodlama
mask_expand10
inpaint_steps20
inpaint_denoise0.90

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. disabled gives you global-only alignment; mask lets you feed your own subject mask; auto is the cheap fallback.
  • inpaint_method - lama recommended, none if you'd rather take the inpaint_mask output 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.

CategoryTrent/Image

Inputs (18)

NameTypeDefaultDescription
original_imageIMAGE
stylized_imageIMAGE
scale_rangeoptFLOAT0.050.01–0.2Maximum scale deviation (0.05 = +/- 5%)
translation_rangeoptINT324–128Maximum translation in pixels
search_precisionoptCOMBObalancedSearch quality vs speed tradeoff
enable_rotationoptBOOLEANtrueEstimate small global rotation during alignment
max_rotation_degoptFLOAT3.00–15Maximum rotation to search (degrees)
allow_anisotropic_scaleoptBOOLEANfalseSeparate X/Y scale - fixes aspect-ratio drift, slight risk of absorbing content differences
visualization_modeoptCOMBOoverlayVisualization type for difference map output. score_map shows the alignment residual before/after.
subject_modeoptCOMBObirefnetdisabled: global only | auto: simple detection | birefnet: high-quality AI | mask: use provided
subject_maskoptMASKOptional mask for subject (for mask mode)
conform_to_originaloptFLOAT1.00–1Conform stylized to original (0=keep stylized, 1=match original)
max_subject_shiftoptINT1500–2048Skip subject correction when the detected move exceeds this many pixels - guards against segmentation mismatch flinging content across the frame (0 = no limit)
fill_transform_edgesoptBOOLEANtrueInpaint edges when scaling/repositioning creates gaps
inpaint_methodoptCOMBOlamanone: 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_expandoptINT100–50Pixels to expand mask before inpainting
inpaint_stepsoptINT205–50Diffusion steps per pass (void method only)
inpaint_denoiseoptFLOAT0.900.5–1Unused (kept for old workflow compatibility)

Outputs (5)

NameTypeDescription
aligned_imageIMAGE
difference_mapIMAGE
alignment_infoSTRING
subject_maskMASK
inpaint_maskMASK