How to do Basic Outpainting in ComfyUI: A Step-by-Step Guide

Prompting Pixels
Kinomoto.Mag AI
Published in
5 min readMay 1, 2024

Sometimes you want an image to be just a bit larger, and that’s where outpainting comes in — a powerful technique that can extend an image in any direction, generating a coherent background outside of the original view.

Diffusion models are perfect candidates for this task, as they can learn to predict a plausible extension of the original image.

Here’s how you can do it in ComfyUI:

👉 Want to power-up your AI art skills? Then consider signing up for one of the FREE Prompting Pixels courses.

Step 1: Loading Your Image

For this outpainting example, I am going to take a partial image I found on Unsplash of a woman sitting at a desk, writing, and the back part of her body has been cropped out, so it’s a perfect candidate for outpainting.

Here’s the original source image:

First, I load the image into ComfyUI, making sure it’s in the correct format and resolution for processing (ideally, the image should have an edge at least 512 pixels long when using a Stable Diffusion 1.5 base model — 1024 for SDXL).

You can either double-click on the workspace and search for Load Image or right-click and find it in the context menu (Add Node > Image > Load Image):

And then find the partial image on your computer, then click Load to import it into ComfyUI.

Step 2: Pad Image for Outpainting

The Load Image node now needs to be connected to the Pad Image for Outpainting node, which will extend the image canvas to the desired size. You can find this in the Add Node > Image > Pad Image for Outpainting menu or by searching for it in the node search bar.

Once connected via noodle between the two nodes, the image is now padded to the desired size, ready for outpainting:

In this case, I’m going to extend the image to the right, so I’ll pad the right side of the image by 200 pixels. Then I’ll also set the feathering to 40, which applies a gradients-based blending effect at the edge of the extended image, ensuring a seamless transition between the original and extended parts.

Step 3: VAE Encode (for Inpainting)

While the name doesn’t suggest it, the VAE Encode (for inpainting) node is a crucial step in the outpainting process.

This node encodes the image information into a format that can be used by the image generation model, allowing it to understand the context and details of the original image.

A default grow_mask_by of 6 is fine for most use cases.

It also passes the mask, the edge of the original image, to the model, which helps it distinguish between the original and generated parts. To use this node, simply connect the image and mask outputs of the Pad Image for Outpainting node along with the VAE from the Load Checkpoint or Load VAE node that you are using to generate the outpainted image.

When outpainting, you need to use an inpainting checkpoint. These checkpoints are trained on partial images, which is effectively what you are adapting upon.

In this case, I’m using the dreamshaper_8Inpainting checkpoint, which is specifically designed for inpainting tasks.

Once connected, the node will encode the image as a Latent and then you’ll pass it to the KSampler for sampling from the latent space.

Step 4: Defining Your Prompt

The prompt, both positive and negative, will help guide the image generation model to produce an outpainted image that meets your desired outcome.

In this case, I’ll define a prompt that describes the original image and its context, such as the woman sitting at the desk, the window behind her, and the overall atmosphere of the scene.

Step 5: KSampler Settings

This is largely dependent on the model that you plan to use. So in this case, you’ll want to review the model card and any of the notes that the author of the model has provided.

Additionally, using fixed seed values can be helpful for debugging any issues that may arise during the outpainting process, ensuring that the results are consistent and reproducible.

Step 6: Generate and Review Outputs

Now all that is needed is to simply click the “Generate” button, and ComfyUI will use the diffusion model to outpaint the image based on the provided prompt and settings. You’ll want to look for coherent and visually appealing results, considering factors such as the quality of the generated background, the continuity of the scene, and the overall realism of the resulting image.

Here’s our before and after comparison:

Always blows my mind at how cool this process is!

If necessary, you can refine your prompt, adjust the model settings, or experiment with different variations to achieve the desired outcome.

Some common problems folks will have will be a harsh transition between the original and generated parts or trying to expand too far or too many edges, especially when dealing with complex scenes or objects. In such cases, it’s essential to work bit by bit, carefully adjusting the settings and prompt to achieve a seamless integration of the original and generated parts.

Bonus Section

While the above steps will give you a solid foundation for outpainting, there are some additional techniques you can use to further refine your results.

One approach is to use ControlNet+LaMa, which can provide even more consistent and realistic results, especially when dealing with complex scenes or objects.

We’ll cover this in a separate guide. However, to get started you could check out the ComfyUI-Inpaint-Nodes custom node.

--

--

Prompting Pixels
Kinomoto.Mag AI

Official account for Prompting Pixels (YT Channel & Website)