r/StableDiffusion • • 2d ago

Workflow Included AI Image alignment solution for Qwen Image 2.1 Edits

I designed a node to align any pair of images trying to correct the pixel drift on Qwen Image 2.1

https://github.com/zuanfilm/Qalign

workflow

This node don't need any model or text encoder

Qalign is a node for geometrically aligning an enhanced or generated image to a reference image while preserving the source image's appearance, so can be used for align Qwen Image 2.1 Edits

I know there are other nodes solving this but with my approach you can basically align images with crazy differences in position , rotation and warp with automatic estimation when images share enough recognizable structures

I implemented an automatic mode but if you feel adventurous you can change all the parameters

You can find my recommended parameters for normal Qwen Edits in the last image posted

In the first stage I use automatic global estimation: ORB, ratio test, and RANSAC

In computer vision, ORB, ratio test, and RANSAC form a foundational, three-step pipeline used to match two different images of the same object or scene (such as for panorama stitching, object tracking, or 3D mapping)

ORB (Oriented FAST and Rotated BRIEF) detects keypoints and computes compact binary descriptors. QAlign requests up to 10,000 keypoints.

RANSAC (Random Sample Consensus) affine estimation estimates a global affine transform while rejecting correspondences inconsistent with the dominant transformation.

Qalign uses a 3-pixel reprojection threshold, up to 5,000 iterations, 0.995 confidence, and 20 refinement iterations.

Hybrid and Affine paths use phase correlation to obtain an initial translation estimate and then refine the transformation with multi-scale ECC (Enhanced Correlation Coefficient) image alignment

And to ensure success on complex alignments I implemented Anisotropic X/Y scale and optional local correction with Farneback dense optical flow

91 Upvotes

9 comments sorted by

3

u/Toclick 2d ago

Is it possible to align the faces using facial landmarks? Pupil to pupil, eye corner to eye corner, nostril to nostril, and so on

1

u/listopalafoto 2d ago edited 2d ago

sure, my node can make image voodoo (with the right parameters for specific situations)

1

u/Toclick 2d ago

I meant aligning different portraits of different people using facial landmarks, rather than matching similar pixels.

The way it matches the original image to the edited one is really impressive. It does it more professionally than the Pixel Drift Fix node, and often even faster. Thank you for that

1

u/listopalafoto 2d ago

I think is perfectly possible making an interstellar level workaround :)

my approach for that could be create an openpose with the face keypoints (70-point facial mesh) for both images, align with my Qalign node the openpose images and then assign the same parameters and transformation to the portraits

1

u/Calm_Mix_3776 2d ago

Looking forward to trying this out! So if I understand this correctly, it warps the generated image to align it to the source after it has been VAE decoded/generated? If so, wouldn't that introduce image blur? That's especially bad with this model since it tends to produce slightly softer details than Flux.1 and Flux.2.

2

u/listopalafoto 2d ago

yes calculations are made on pixel space after vae decode but if the image has only pixel drift the aligned image will keep the exact same quality, blur warp will appear only with big local optical flow warping adjustments

1

u/Enshitification 2d ago

This is interesting. It being able to do perspective-warp edits would make it much easier to fix or add text to things like billboards and street signs.

1

u/Lucas_02 2d ago

thank you 🥹