ComfyUI Node

Pixel Drift Fix

Put the Pixels Back Where the Edit Model Moved Them

By Mozer·Created 3 months ago·Updated 3 months ago· 31
Pixel Drift Fix
  • source_image
  • edited_image
  • fixed_image
methodflat_4_points
max_mesh_points400

The problem it solves

You know the feeling: you run an instruction editor like Qwen-Image-Edit or Flux 2 Klein, the object gets removed exactly right, and yet the whole frame has quietly shifted three pixels left and the face is now a degree off-kilter. That's not your imagination. These models don't patch your image - they re-emit the entire frame and hope the unchanged pixels stay put. The Qwen-Image-Edit panel in our knowledge base names it directly: "the model re-emits the whole frame, so pixels nobody asked about move, faces drift on a chain of edits." Upscalers pull the same stunt on a smaller scale, subtly re-cropping or skewing framing during a detail pass.

PixelDriftFix is the glue you bolt on after the fact. It takes your original and the edited/upscaled version, finds matching features between them, and warps the edited image back into geometric alignment with the source. It won't recover pixel-perfect identity - this is registration, not inpainting - but it turns "the framing drifted" from a silent corruption into a non-issue.

How it works

The mechanism is classic computer vision, and it's all local - no API, no model files, nothing to download. Under the hood the node:

  1. Converts both images to grayscale and runs SIFT keypoint detection with unusually sensitive settings (contrast threshold at 0.01) so it can find matches even on flat, smooth regions.
  2. Matches keypoints with a brute-force matcher plus Lowe's ratio test at 0.80, which throws out ambiguous matches.
  3. Fits a homography with RANSAC - a perspective transform that maps the edited image onto the source's geometry.
  4. Applies that transform, resizing the output to exactly the source's dimensions.

Then method picks the warp quality. flat_4_points (the default, and the author's recommendation) applies one clean global perspective warp - around 4 seconds and right for almost everything. mesh is experimental: a dense piecewise-affine warp from scikit-image that can bend locally, capped by max_mesh_points. It's meant for complex local deformations, but the README's own verdict is "experimental, worse and slow," so treat it as a last resort.

The inputs that matter

Only four, which is refreshing:

  • source_image - your original.
  • edited_image - the drifted result.
  • method - flat_4_points or mesh; leave it on the default.
  • max_mesh_points - ignored unless you picked mesh. 400 is good and fast (~4s); 10000 is best quality and about 90 seconds.

The single output, fixed_image, wires straight into PreviewImage or SaveImage. The bundled restoration workflow chains it into an ImageBlend so the fixed result gets blended with the original - handy for old-photo restoration, where you restore and upscale, then snap the restored version back onto the original framing.

Installation

Install via ComfyUI Manager using the git URL, then restart ComfyUI. Or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/Mozer/ComfyUI-PixelDriftFix

Its requirements.txt pulls in opencv-python, scikit-image, numpy, and torch. The first two are the ones that might not already be in your install; ComfyUI ships with torch and numpy. There are no weights, no checkpoints, no HF downloads - the whole thing is ~250 lines of CV code.

Common issues

  • "It did nothing." Check the console. If it found fewer than 10 matching points, it logs a warning and passes the edited image through untouched. The two images have to actually be similar - at least 10 matching features - so a heavy recomposition (new background, rotated subject, full style transfer) won't have enough inliers to align.
  • "There's a strip of duplicated pixels on the edges." Expected. The warp uses border replication, so edges get stretched when the transform pushes outside the frame. The README calls this out; crop a few pixels or just live with it.
  • "The output size changed." By design - it resizes to the source's exact dimensions.

Where people get burned is expecting magic on dissimilar images. This is an alignment pass, not a compositor. If you need the unedited regions to survive byte-for-byte, the Inpaint Crop and Stitch pattern is still the right tool; PixelDriftFix is for when the whole frame drifted and you'd rather fix it than re-mask it.

Categoryimage/processing

Inputs (4)

NameTypeDefaultDescription
source_imageIMAGE
edited_imageIMAGE
methodCOMBOflat_4_pointsflat_4_points gives better results and is faster. Mesh is experimental.
max_mesh_pointsINT400100–10000Only used when method is set to 'mesh'. Higher values increase alignment accuracy but take longer. 400 = good/fast (~4s), 10000 = best quality (~90s).

Outputs (1)

NameTypeDescription
fixed_imageIMAGE