ComfyUI Node

SMC Affine Compand

Measure the drift, then pull it back.

By xmarre·Created 6 months ago·Updated 6 months ago· 0
SMC Affine Compand
  • anchor_image
  • target_image
  • mask
  • original_image
  • profile
  • corrected
  • warped_target
  • diagnostics
  • stats_json

SMC Affine Compand (class SMCAffineCompand) is the correction engine of the pack's affine path - the older, more explicit sibling of SMC Anchor-Guided Compand. Where the anchor-guided node derives a radial inward flow from a mask and estimates expansion, this one fits an actual affine transform (scale + translation) between your anchor and your drifted target, warps the target inward along it, restores low-frequency color toward the anchor, re-adds detail, and hands you the corrected image plus a diagnostics panel.

It's the node to reach for when you want to understand the correction, not just apply it - the README frames the affine path as the diagnostic/interpretable route, and the pack's Impact Pack hook also runs this path internally. If you're correcting FLUX.2 Klein detail-crop drift - the outward zoom, the washout, the chroma flattening - and you want to see the estimated scale/translation that drove the fix, this is the workflow.

How it works, briefly

  1. Blur anchor and target with stable_sigma; compute a mask-weighted interior weight.
  2. Estimate an affine that maps the target's structure onto the anchor's (the same math as SMC Affine Estimate Drift), clamped by max_shrink/max_expand so it shrinks but never blows up.
  3. Warp the target along that transform with grid_sample (warped_target), smoothed by translate_strength and the interior weight so the edges stay put.
  4. Restore color in Oklab: pull luminance/chroma means and standard deviations toward the anchor, with anchor_pull blending in the anchor's actual colors and compaction_to_chroma mapping measured compaction to a chroma boost.
  5. Re-add detail (detail_retain), tether the boundary to the original (boundary_tether), and paste back inside the mask (blend_back_to_target).

Inputs that matter

  • anchor_image, target_image - required. The stable low-res reference and the drifted high-res result.
  • mask (optional) - where the correction applies; no mask = whole frame.
  • original_image (optional) - if supplied, the boundary ring is tethered to its low-frequency content, which helps when you're pasting back into a larger frame.
  • profile (optional) - an SMC_PROFILE from SMC Affine Profile. Skip it and the node uses the profile defaults.

Outputs

  • corrected - wire to Save/Preview.
  • warped_target - the warped intermediate, for inspection.
  • diagnostics - a side-by-side panel: anchor | target | corrected | heatmap+mask. Genuinely useful; the heatmap shows where pixels moved most.
  • stats_json - the full drift stats (scale, compaction, translation, chroma ratios) as JSON.

Install & gotchas

Same pack, trivial install:

cd ComfyUI/custom_nodes
git clone https://github.com/xmarre/ComfyUI-StableManifoldCompander

or ComfyUI Manager (search "Stable Manifold Compander"). No extra dependencies, no model downloads. Watch the defaults: max_expand is 0, so this node will never grow content - if your correction is making things look tight or shrunken, that's expected at full geometry_strength; dial geometry_strength down or nudge max_shrink. And remember it's a heuristic affine fit, not optical flow - it fixes global scale/translation drift, not per-region warping. For localized radial drift, the anchor-guided SMC Compand is the better tool.

CategoryStableManifoldCompand/Affine

Inputs (5)

NameTypeDefaultDescription
anchor_imageIMAGE
target_imageIMAGE
maskoptMASK
original_imageoptIMAGE
profileoptSMC_PROFILE

Outputs (4)

NameTypeDescription
correctedIMAGE
warped_targetIMAGE
diagnosticsIMAGE
stats_jsonSTRING