High-Resolution Inpainting with Qwen Image 2.1 in ComfyUI
Inpainting is a powerful technique for replacing objects, modifying specific regions, and refining images without regenerating the entire composition. However, when working with high-resolution images, maintaining pixel consistency and preserving original details can be particularly challenging.
In this article, I’m going to share an inpainting workflow I built using Qwen Image 2.1 in ComfyUI. This workflow allows you to modify specific areas of an image while preserving the original pixels outside the masked region. It also supports reference-based inpainting, allowing you to reproduce the appearance of a specific object with impressive accuracy.
YouTube Tutorial:
Introduction
High-Resolution Inpainting
Let’s start with an example. The original image has a resolution of 6720 × 4368 pixels. Using this workflow, I replaced a bouquet of flowers with a handbag.
Rather than regenerating the entire image, the workflow processes the region surrounding the masked area and stitches the generated result back into the original image. In this example, only the pixels inside the masked area were changed, while everything outside remained exactly the same, including all the original fine details.

This makes the workflow particularly useful for high-resolution photography, product photography, and professional image editing, where preserving original image quality is essential.
Reference-Based Inpainting
Another powerful feature of this workflow is its ability to perform inpainting using a reference image.
In another example, I replaced the bouquet with a different handbag by providing an image of the desired handbag as a reference.

The generated handbag contains a considerable amount of fine detail and looks almost identical to the reference image.

Instead of relying entirely on a text prompt to describe the replacement object, we can use a reference image to communicate its appearance directly to the model.
Key Features of the Workflow
- High-resolution inpainting without regenerating the entire image.
- Preservation of original pixels outside the masked area.
- Optional reference images for accurate object replacement.
- Reduced pixel drifting through image resizing and a consistency LoRA.
- Custom sigma values for improved detail generation.
- Two-pass inpainting for additional refinement.
- Seamless reintegration of the generated region into the original image.
Step 1: Masking and Cropping the Original Image
The first stage of the workflow prepares the original image and isolates the region we want to modify.
Instead of sending the entire high-resolution image to the model, we crop a smaller region based on the mask. This allows the model to concentrate on the area that actually requires editing.
Creating a Mask Using the Mask Editor
First, upload the original image and create a mask over the region you want to inpaint.
- Load your original image into the workflow.
- Open the Mask Editor.
- Use the brush tool to paint over the object or region you want to replace.
- Save the mask and return to the workflow.
In my example, I painted a mask over the bouquet because I wanted to replace it with a handbag.

Make sure the mask covers the entire object you intend to replace. Any unwanted parts left outside the masked region may remain visible in the final image.
Cropping the Image with the Inpaint Crop Node
Next, the Inpaint Crop node crops the uploaded image based on the mask.
The cropped image contains the target region and surrounding visual information that helps the model understand the context of the edit, including the background, lighting, and nearby objects.

You can preview both the cropped image and its corresponding mask directly within this node. These previews are particularly useful for checking whether the cropped region contains enough contextual information for the model to generate a natural-looking replacement.
Adjusting Crop Settings to Prevent Visible Seams
Sometimes, you may encounter unwanted artifacts after inpainting, such as unnatural transitions or visible seams where the generated region meets the original image.
If this happens, try adjusting the parameters in the Inpaint Crop node.
The cropping and mask-related settings can influence how naturally the generated region blends into the original image. You can hover your mouse over each parameter to display a tooltip explaining its function.
Depending on your image, some experimentation may be necessary to achieve the best result.
Applying a Green Overlay to the Masked Area
I also use the Inpaint Crop node to apply a green overlay to the masked area, with its opacity set to 50%.
The purpose of this overlay is to provide Qwen Image 2.1 with a clear visual indication of which region needs to be edited.
Conceptual illustration of the green overlay used to identify the target editing region.
By using 50% opacity, the original content remains partially visible underneath the green overlay while the model receives a strong visual cue identifying the target region.
Later, in the text prompt, we can explicitly instruct the model to replace the object covered by the green area.
Step 2: Resizing the Cropped Image to Reduce Pixel Drifting
Moving on to the second node group, these nodes resize the cropped image generated by the first group.

The primary purpose of this step is to reduce pixel drifting during image generation.
Pixel drifting occurs when the generated image introduces small spatial changes to elements that should otherwise remain unchanged. These changes may include slight shifts in object positions, edges, textures, or background details.
While these differences may not be particularly noticeable when viewing the generated image independently, they can become problematic when stitching the cropped image back into the original.
Even a small misalignment can potentially create visible seams or unnatural transitions.
Resizing the cropped image appropriately before sending it to the model helps minimize this issue.
I explained the principles behind this resizing technique in my previous article, so I won’t go into the technical details again here. However, this step plays an important role in maintaining pixel consistency throughout the workflow.
Step 3: Configuring Qwen Image 2.1 for Inpainting
The next node group handles the first inpainting pass. This is where Qwen Image 2.1 generates the replacement object based on the cropped image, text prompt, and optional reference image.
Loading the INT8 Qwen Image 2.1 Model
For this workflow, I’m using the INT8 version of Qwen Image 2.1, together with a consistency LoRA.

The model is responsible for interpreting the visual information in the cropped image, identifying the region covered by the green overlay, and generating the requested replacement object.
Using a Consistency LoRA to Prevent Pixel Drifting
In addition to resizing the cropped image, I use a consistency LoRA to further reduce unwanted pixel drifting.
The consistency LoRA used in this workflow was trained by a different creator from the one I introduced in my previous article.
After testing both LoRAs, I found that this particular version performs better for this inpainting workflow.
In most cases, setting the LoRA strength to 0.5 is sufficient to eliminate noticeable pixel drifting in my tests.
Why Pixel Consistency Matters for Inpainting
Maintaining pixel consistency is especially important because the generated result at this stage is still a cropped image rather than the complete original image.
Later, we need to stitch this generated crop back into the original high-resolution image.
If the surrounding pixels have shifted during generation, the generated crop may no longer align properly with the original image. This can result in visible seams, misaligned edges, distorted background elements, or other unwanted artifacts.
By combining image resizing with a consistency LoRA, we can improve spatial consistency and make the final stitching process more reliable.
Providing a Reference Image and Writing the Inpainting Prompt
For reference-based inpainting, I provide an additional image containing the object I want to generate.
In this example, the first image is the cropped original image with the green overlay, while the second image is the reference image of the handbag.
Both images are used by the Text Encode Qwen Image 2.1 node, together with the text prompt.
Here’s the prompt I used:
replace the bouquet covered by the green area in image 1 with the handbag in image 2; adjust the lighting to merge the handbag naturally into the surrounding
This prompt provides three important instructions to the model:
- Identify the target region: Locate the bouquet covered by the green overlay in the first image.
- Specify the replacement object: Use the handbag from the second image as the visual reference.
- Adjust the lighting: Adapt the lighting of the generated handbag so that it blends naturally into the surrounding environment.
The lighting instruction is particularly useful because the reference image may have been captured under completely different lighting conditions.
Rather than simply reproducing the handbag’s appearance, we want the model to integrate it naturally into the original scene while retaining its distinctive visual characteristics.
Using Custom Sigma Values for Enhanced Details
You may have noticed that I’m not using the standard KSampler node in this workflow.
Instead, I’m using a sampler that allows me to manually specify the sigma values.

Sigma values represent the noise levels used at different stages of the diffusion sampling process. Normally, these values are calculated automatically by the selected scheduler.
However, manually defining the sigma values gives us more control over the sampling process.
Through experimentation, I found that the custom sigma values used in this workflow allow the model to generate more fine details than the automatically calculated values produced by the scheduler I tested.
This is particularly beneficial when generating objects such as handbags, where small visual details, material textures, stitching, and decorative elements can significantly influence the realism of the result.
Reviewing the First Inpainting Result
After the first inpainting pass is complete, we can preview the generated cropped image.
In my example, the green overlay has disappeared, and the bouquet has been successfully replaced with a handbag.

The generated handbag looks very close to the reference image provided to the Text Encode Qwen Image 2.1 node.
Although the initial result already looks quite good, we can improve it further by adding another inpainting pass.
Step 4: Enhancing Details with a Second Inpainting Pass
The lower node group performs a second pass of inpainting.

Rather than treating the output of the first pass as the final result, this additional stage gives the model another opportunity to refine the generated image and bring out more fine details.
Refining the Initial Inpainting Result
The first inpainting pass is primarily responsible for establishing the replacement object, its overall appearance, and its integration into the surrounding scene.
The second pass focuses on further refining that result.
This additional refinement can help improve surface textures, enhance small visual details, and reduce certain artifacts that may remain after the initial generation.
The two-pass approach is particularly useful when working with reference images containing intricate objects or when the final image will be viewed at a high resolution.
Adjusting Denoising Strength
For the second inpainting pass, I set the denoising strength to 0.5.
This gives the model an opportunity to refine the generated image while retaining much of the visual information established during the first pass.
However, if you still notice artifacts in the generated image, you can try increasing the denoising strength.
A higher denoising strength gives the model more freedom to modify the existing result, which may help correct unwanted artifacts. However, it can also introduce additional changes, so it’s important to find a suitable balance between refinement and consistency.
| Denoising strength | Expected behavior |
|---|---|
| Below 0.5 | More conservative refinement with greater preservation of the first result. |
| 0.5 | Default setting used in this workflow for detail enhancement. |
| Above 0.5 | Greater freedom to correct artifacts, with an increased possibility of unwanted changes. |
I recommend starting with the default value of 0.5 and adjusting it based on the quality of your generated image.
Optional: Inpainting Without a Reference Image
Although reference-based inpainting is one of the key features of this workflow, using a reference image is completely optional.
If you simply want to replace an object based on a text description, you can bypass the two nodes responsible for providing the reference image.
To perform inpainting without a reference image:
- Bypass the two reference-image-related nodes.
- Keep the cropped image with the green overlay as the visual input.
- Modify the text prompt to describe the object you want to generate.
- Run the workflow as usual.
For example, instead of instructing the model to reproduce a handbag from a second image, you could use the following prompt:
Text-only inpainting prompt
Replace the bouquet covered by the green area with an elegant brown leather handbag with gold hardware. Adjust the lighting and shadows to blend the handbag naturally into the surrounding environment.
In this case, the model generates the handbag based on the text description rather than attempting to reproduce a specific reference object.
This flexibility makes the workflow suitable for both precise object replacement and more creative image editing tasks.
Step 5: Stitching the Inpainted Image Back into the Original
Once the inpainting process is complete, we can move on to the final node group.
The purpose of this group is to select the preferred generated image and stitch it back into the original high-resolution image.
Selecting the Final Image with the Image Switch Node
Since this workflow performs two passes of inpainting, we have two generated images available:
- The initial result from the first inpainting pass.
- The refined result from the second inpainting pass.
The Image Switch node allows us to choose which of these two images will be stitched back into the original image.

Usually, I select the second image because it has gone through the additional detail-enhancement process.
However, if the first result looks better or preserves the appearance of the reference object more accurately, you can select that image instead.
Having this option gives us greater control over the final output without requiring us to restructure the workflow.
Stitching the Generated Crop into the Original Image
After selecting the preferred generated image, the stitching node reintegrates the processed region into the original image.

This is where all the previous steps come together.
The masking and cropping process isolates the target region, while the resizing technique and consistency LoRA help maintain pixel alignment. The two inpainting passes generate and refine the replacement object before the selected result is stitched back into the original image.
Conceptual illustration of reintegrating the generated region into the original image.
Instead of replacing the entire original image with an AI-generated version, the workflow reintegrates only the necessary edited region, preserving the original image outside the mask as much as possible.
Reviewing the Final High-Resolution Result
And that’s it! We’ve successfully completed the inpainting process.
In the final result, the bouquet has been replaced with the handbag, while the surrounding elements retain their original appearance and details.
Most importantly, the original image retains its high resolution of 6720 × 4368 pixels without requiring the model to regenerate the entire image at that resolution.
This approach is especially valuable when working with large images that already contain a considerable amount of fine detail. Rather than sacrificing those details through full-image regeneration, we can focus the generative process on the specific region that requires modification.
Conclusion
By combining mask-based cropping, image resizing, a consistency LoRA, custom sigma values, and two-pass inpainting, this workflow provides a powerful approach to high-resolution image editing with Qwen Image 2.1 in ComfyUI.
One of the biggest advantages of this approach is that we don’t have to sacrifice the original image quality simply because we want to modify a small portion of it.
Whether you’re replacing products in commercial photography, modifying specific objects in an existing composition, or experimenting with creative image editing, this workflow gives you greater control over the generated content while preserving the original details.
The ability to use optional reference images makes it even more versatile, allowing you to achieve both accurate object reproduction and creative text-based inpainting within the same workflow.
If you’d like to download this workflow and experiment with it yourself, please consider joining our community and supporting my work.
Thank you for reading, happy creating, and I’ll see you in the next article!
