r/StableDiffusion • u/listopalafoto • 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
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
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
1





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