Intermediate

Image Editing with DALL-E

Learn inpainting, outpainting, style transfer, and image variation techniques to refine and extend your DALL-E creations.

Inpainting

Inpainting replaces specific regions of an image while keeping the rest intact. You provide the original image and a mask indicating which areas to regenerate:

Python (DALL-E 2 API)
from openai import OpenAI

client = OpenAI()

# The mask should be the same size as the image
# Transparent (alpha=0) areas will be regenerated
# Opaque areas will be preserved

response = client.images.edit(
    model="dall-e-2",
    image=open("room.png", "rb"),
    mask=open("mask.png", "rb"),
    prompt="A beautiful vase of sunflowers on the table",
    n=1,
    size="1024x1024",
)

print(response.data[0].url)

Inpainting in ChatGPT

With DALL-E 3 in ChatGPT, you can describe edits conversationally:

  • "Remove the person in the background"
  • "Replace the sky with a dramatic sunset"
  • "Add a cat sitting on the chair in the corner"
  • "Change the color of the building from gray to red brick"

Outpainting

Outpainting extends an image beyond its original borders, generating new content that seamlessly continues the scene:

Outpainting Approach
Steps to outpaint via the API:

1. Create a new, larger canvas (e.g., 1024x1024)
2. Place your original image in the center
3. Create a mask where the empty areas are transparent
4. Use the edit endpoint with a prompt describing
   what should fill the extended areas

In ChatGPT:
Simply ask: "Extend this image to show more of the
surrounding landscape" or "Zoom out to reveal
more of the scene"

Style Transfer

Convert an image from one style to another using ChatGPT with DALL-E 3:

Style Transfer Examples
# Upload an image to ChatGPT and ask:

"Recreate this photo as a Studio Ghibli animation"

"Transform this into a Van Gogh-style oil painting
with swirling brushstrokes"

"Convert this to a minimalist vector illustration
with flat colors"

"Make this look like a vintage 1950s poster
advertisement"

"Reimagine this as pixel art in a retro video
game style"

Image Variations

Create variations of existing images that maintain the overall composition but introduce creative differences:

Python
# API variations (DALL-E 2)
response = client.images.create_variation(
    model="dall-e-2",
    image=open("original.png", "rb"),
    n=4,
    size="1024x1024",
)

# ChatGPT approach (DALL-E 3)
# Upload an image and ask:
"Create 4 variations of this image, keeping the
same general composition but with different
color palettes and lighting"
💡
Pro tip: For the best editing experience with DALL-E 3, use ChatGPT rather than the API. ChatGPT understands your intent better and can handle complex editing requests that are difficult to express in a single API call.

What's Next?

The final lesson covers best practices including content policies, cost optimization, ethical considerations, and professional workflow tips.