ComfyUI-QwenImageEdit-LockPixel
LockPixel is a ComfyUI custom node pack for Qwen-Image-Edit workflows where pixel drift, small shifts, or subtle zoom-like deformation must be avoided.
Nodes (4)
ComfyUI-QwenImageEdit-LockPixel
English
LockPixel is a ComfyUI custom node pack for Qwen-Image-Edit workflows where pixel drift, small shifts, or subtle zoom-like deformation must be avoided.
Qwen-Image-Edit can produce visible alignment drift when the reference latent grid and the sampler latent grid are created at different sizes. This node pack avoids that path by padding the input image to a 32 pixel grid, encoding that padded image once with the VAE, and using the same latent grid for both reference_latents and KSampler latent_image.
What It Solves
- Prevents the common drift path caused by Qwen's internal 1MP reference-image resize.
- Keeps
reference_latentsand sampler latent dimensions aligned. - Preserves the original image size by cropping padding away after VAE decode.
- Works well for line extraction, retouching, partial edits, manga panels, and other workflows where layout alignment matters.
Installation
Place this folder in your ComfyUI custom_nodes directory:
ComfyUI/custom_nodes/ComfyUI-QwenImageEdit-LockPixel
Restart ComfyUI. The nodes will appear under:
qwen image edit/lockpixel
Nodes
LockPixel Pad Image: pads an image to a multiple of 32 without resizing.LockPixel Qwen Encode: creates Qwen conditioning and a sampler latent from the same padded image.LockPixel Apply Reference: attaches an existing latent asreference_latents.LockPixel Crop Back: removes padding after VAE decode.
Basic Workflow
Load Image
-> LockPixel Pad Image
-> LockPixel Qwen Encode
-> KSampler positive
-> KSampler latent_image
KSampler
-> VAE Decode
-> LockPixel Crop Back
Use the latent output from LockPixel Qwen Encode as KSampler latent_image. This is the important part: the conditioning reference latent and sampler latent must come from the same padded image.
Example Workflow
A sample workflow is included here:
examples/qwen_image_edit_lockpixel_basic.json
After importing it into ComfyUI, replace the checkpoint and input image names with files available in your environment.
Notes
- Do not pass the VAE into the standard
TextEncodeQwenImageEditPlusfor the same reference image in this workflow. - Qwen-VL image input is still resized for text/vision understanding. The spatial reference latent is not resized to 1MP.
- This node pack fixes the latent-grid mismatch path. It does not guarantee pixel-identical values in unedited regions because VAE encode/decode itself is lossy.
- For strict unedited-region preservation, composite the edited output back over the original image with a mask after generation.
Background
This project was created from an investigation into Qwen-Image-Edit pixel drift. The key finding was that drift is not just a simple translation offset. It is often caused by inconsistent resizing and token-grid alignment between the reference image latent and the sampler latent.
The practical rule implemented here is:
reference latent grid == sampler latent grid
References
The implementation and workflow design were informed by these public discussions and related projects:
- QwenLM/Qwen-Image Issue #229: https://github.com/QwenLM/Qwen-Image/issues/229
- ComfyUI Issue #9481: https://github.com/comfyanonymous/ComfyUI/issues/9481
- Reddit r/StableDiffusion discussion: https://www.reddit.com/r/StableDiffusion/comments/1o01e6i/
- Phr00t/Qwen-Image-Edit-Rapid-AIO discussions:
- https://huggingface.co/Phr00t/Qwen-Image-Edit-Rapid-AIO/discussions/26
- https://huggingface.co/Phr00t/Qwen-Image-Edit-Rapid-AIO/discussions/73
- lrzjason/Comfyui-QwenEditUtils: https://github.com/lrzjason/Comfyui-QwenEditUtils
- Qwen-Image-Edit-Lowres-Fix / RoPE interpolation reference: https://huggingface.co/SahilCarterr/Qwen-Image-Edit-Lowres-Fix
- diffusers Issue #12997: https://github.com/huggingface/diffusers/issues/12997
- MyAIForce article on Qwen Edit pixel drift and Crop & Stitch: https://myaiforce.com/fix-pixel-drift-for-qwen-edit/
License
MIT License. See LICENSE.
日本語
LockPixel は、Qwen-Image-Edit でピクセルずれ、小さな位置ずれ、微妙なズーム状の歪みを避けたいワークフロー向けの ComfyUI カスタムノードです。
Qwen-Image-Edit では、参照 latent のグリッドと KSampler に渡す latent のグリッドが別サイズで作られると、目に見える位置ずれが起きることがあります。このノード群は、入力画像を 32px グリッドへ padding し、その padding 済み画像を VAE で一度だけ encode し、同じ latent グリッドを reference_latents と KSampler の latent_image の両方に使います。
解決する問題
- Qwen 側の内部 1MP リサイズに起因する典型的なずれ経路を避けます。
reference_latentsと sampler latent の寸法を一致させます。- VAE decode 後に padding 分を切り戻し、元画像サイズへ戻します。
- 線画抽出、レタッチ、部分修正、漫画コマ処理など、レイアウト維持が重要な用途に向いています。
インストール
このフォルダを ComfyUI の custom_nodes に置きます。
ComfyUI/custom_nodes/ComfyUI-QwenImageEdit-LockPixel
ComfyUI を再起動すると、以下のカテゴリにノードが表示されます。
qwen image edit/lockpixel
ノード一覧
LockPixel Pad Image: 画像をリサイズせず、32 の倍数サイズへ padding します。LockPixel Qwen Encode: 同じ padding 済み画像から Qwen conditioning と sampler latent を作ります。LockPixel Apply Reference: 既存 latent をreference_latentsとして conditioning に追加します。LockPixel Crop Back: VAE decode 後に padding 分を切り戻します。
基本ワークフロー
Load Image
-> LockPixel Pad Image
-> LockPixel Qwen Encode
-> KSampler positive
-> KSampler latent_image
KSampler
-> VAE Decode
-> LockPixel Crop Back
重要なのは、LockPixel Qwen Encode の latent 出力を KSampler の latent_image に接続することです。conditioning 側の参照 latent と sampler 側の latent を、同じ padding 済み画像から作る必要があります。
サンプルワークフロー
サンプル workflow は以下に含まれています。
examples/qwen_image_edit_lockpixel_basic.json
ComfyUI に読み込んだ後、checkpoint 名と入力画像名を自分の環境にあるファイル名へ置き換えてください。
注意点
- このワークフローでは、同じ参照画像を標準
TextEncodeQwenImageEditPlusに VAE 付きで渡さないでください。 - Qwen-VL の画像入力は、文章・画像理解用として 384px 系に縮小されます。ただし、空間位置を決める参照 latent は 1MP へリサイズしません。
- このノード群が防ぐのは latent グリッド不一致によるずれです。VAE encode/decode 自体は非可逆なので、未編集領域の画素値が完全一致することまでは保証しません。
- 未編集領域の厳密な保持が必要な場合は、生成後に mask で元画像と合成してください。
背景
このプロジェクトは、Qwen-Image-Edit のピクセルずれ調査を元に作成しました。調査で重要だった点は、ずれが単純な平行移動だけではなく、参照画像 latent と出力 latent のリサイズ・トークングリッド不一致から発生することがある、という点です。
このノードで実装している実用上のルールは次の通りです。
参照 latent のグリッド == sampler latent のグリッド
出典・参考資料
実装方針とワークフロー設計は、以下の公開情報と関連プロジェクトを参考にしています。
- QwenLM/Qwen-Image Issue #229: https://github.com/QwenLM/Qwen-Image/issues/229
- ComfyUI Issue #9481: https://github.com/comfyanonymous/ComfyUI/issues/9481
- Reddit r/StableDiffusion discussion: https://www.reddit.com/r/StableDiffusion/comments/1o01e6i/
- Phr00t/Qwen-Image-Edit-Rapid-AIO discussions:
- https://huggingface.co/Phr00t/Qwen-Image-Edit-Rapid-AIO/discussions/26
- https://huggingface.co/Phr00t/Qwen-Image-Edit-Rapid-AIO/discussions/73
- lrzjason/Comfyui-QwenEditUtils: https://github.com/lrzjason/Comfyui-QwenEditUtils
- Qwen-Image-Edit-Lowres-Fix / RoPE interpolation reference: https://huggingface.co/SahilCarterr/Qwen-Image-Edit-Lowres-Fix
- diffusers Issue #12997: https://github.com/huggingface/diffusers/issues/12997
- MyAIForce の Qwen Edit ピクセルずれ / Crop & Stitch 解説: https://myaiforce.com/fix-pixel-drift-for-qwen-edit/
ライセンス
MIT License です。詳細は LICENSE を参照してください。