ERNIE-Image Inpainting + Outpainting Complete Guide: Local Redraw and Canvas Expansion

May 2, 2026

ERNIE-Image Inpainting + Outpainting Complete Guide: Local Redraw and Canvas Expansion

From flaw repair to canvas expansion — ERNIE-Image's inpainting and outpainting capabilities let you recreate every image. Whether it's ecommerce product retouching, portrait background replacement, or photographic canvas expansion, this guide walks you through these core editing features step by step.


Part 1: Inpainting vs Outpainting — Core Concepts

Capability Definition Core Use Cases
Inpainting Regenerate specified regions within an image Flaw repair, object removal/addition, style adjustment
Outpainting Expand image beyond existing boundaries Canvas expansion, background extension, composition adjustment

Technical Principle

Both use mask-guided diffusion:

Original Image + Mask
    ↓
VAEEncode → Latent Space
    ↓
Mask region noise injection
    ↓
KSampler + Prompt → Generate mask region
    ↓
VAEDecode → Output repaired/extended image

Key difference: Inpainting masks are inside the image, Outpainting masks are outside the image boundary.


Part 2: Inpainting — 5 Core Scenarios

Scenario 1: Flaw Repair

Action: Mask the flaw area (skin blemishes, product scratches), prompt describes the ideal state.

Prompt Template:

{original image description},
clean skin, smooth texture, professional retouching,
high quality, detailed, natural lighting

Typical uses: Portrait skin retouching, product surface flaw repair, photo spot cleanup.

Scenario 2: Object Removal

Action: Mask the object to remove (strangers, power lines, watermarks), prompt describes the background continuation.

Prompt Template:

{background description},
clean background, natural, seamless,
background continuation, no extra objects

Tip: Make the mask area slightly larger than the target object — give the model "breathing room."

Scenario 3: Object Addition

Action: Mask the target position, prompt describes the object to add.

Prompt Template:

{original image description},
{object to add},
integrated naturally, consistent lighting, matching style,
professional composition

Tip: The closer the added object matches the original image style, the better the integration.

Scenario 4: Style Replacement

Action: Mask the region to restyle, prompt describes the new style.

Prompt Template:

{original image description},
{target style: watercolor painting / oil painting / anime style},
artistic, creative, detailed

Scenario 5: Text Correction

Action: Mask the text area to modify, prompt describes the correct text.

Important: Turn off PE (Prompt Enhancer), as PE may rewrite your specified text content.


Part 3: Outpainting — 3 Core Scenarios

Scenario 1: Canvas Expansion (16:9 → 21:9 Ultra-Widescreen)

Action: Expand left and right, prompt describes scene continuation.

Prompt Template:

{original image description},
wide angle, panoramic view,
continuous background, cinematic composition,
extended scene, ultra wide shot

Typical uses: Photo to cinematic widescreen, desktop wallpaper expansion, social media cover adaptation.

Scenario 2: Background Extension (Full-Body Completion)

Action: Expand bottom/top to supplement the environment.

Prompt Template:

{original image description},
extended {environment},
full body shot, ground visible, natural surroundings,
professional photography, consistent lighting

Typical uses: Half-body → full-body portrait, product image background completion.

Scenario 3: Multi-Direction Expansion

Action: First expand left/right, then top/bottom, step by step.

Tip: Expand no more than 30% per step — stepwise expansion yields more stable quality.


Part 4: ComfyUI Inpainting Complete Workflow

Node Connections

[Load Checkpoint] → ERNIE-Image 8B
    ↓
[LoadImage] → Original image
    ↓
[ImageToMask] → Generate mask (or draw manually)
    ↓
[VAEEncode] → Latent
    ↓
[LatentComposite] → Mask + Prompt
    ↓
[KSampler] → Inpaint steps
    ↓
[VAEDecode] → Output repaired image
    ↓
[SaveImage] → Save result

Parameter Tuning Table

Parameter Recommended Notes
Inpaint Steps 20-30 Turbo: 8-12
CFG Scale 5.0-8.0 Prompt guidance strength
Mask Strength 0.8-1.0 Repair intensity (higher = more aggressive)
Denoise 0.5-0.8 Redraw degree (lower = more conservative)
Mask Blur 4-8 Edge blur for smooth transition
Scheduler Euler / DPM++ Euler = fast, DPM++ = higher quality

Turbo Mode Parameters

Parameter Turbo Value Standard Value
Steps 8-12 20-30
CFG 4.0-6.0 5.0-8.0
Speed ~2s/image ~15s/image

Part 5: ComfyUI Outpainting Workflow

Node Connections

[LoadImage] → Original image
    ↓
[ImageScaleByFactor] → Scale to target size (optional)
    ↓
[ImagePadForOutpainting] → Fill blank areas
    ↓
[ImageToMask] → Generate outpainting mask
    ↓
[VAEEncode] → Latent
    ↓
[KSampler] → Outpainting steps
    ↓
[VAEDecode] → Output expanded image
    ↓
[SaveImage] → Save result

Key Parameters

Parameter Recommended Notes
Expand Amount 50%-100% Expansion ratio (keep ≤50%)
Steps 20-30 Generation steps
CFG 5.0-7.0 Guidance strength
Denoise 0.6-0.8 Creativity level
Fallback Pixels 8-16 Edge overlap pixels

Part 6: Detailed Practical Cases

Case 1: Ecommerce Product Background Replacement

Original: White background product photo (standard ecommerce image)

Inpainting Flow:

  1. Mask product body (inverse mask)
  2. Prompt: product on wooden table, warm natural lighting, lifestyle scene, shallow depth of field, professional product photography
  3. Denoise: 0.7, Mask Blur: 6
  4. Output: Product lifestyle scene, ready for social media

Value: Generate 10 scene variations from one white-background photo — no reshoot needed.

Case 2: Portrait Full-Body Expansion

Original: 4:3 half-body portrait

Outpainting Flow:

  1. Expand bottom by 50%
  2. Prompt: full body portrait, standing in garden, natural sunlight, flowers, professional photography, full body shot, elegant pose
  3. Denoise: 0.6, Steps: 25
  4. Output: Full-body portrait with natural background extension

Case 3: Photo Flaw Removal (Stranger/Watermark Removal)

Original: Landscape photo with strangers/watermarks

Inpainting Flow:

  1. Precisely mask target area
  2. Prompt: clean landscape, no people, natural scenery, clear sky, professional photography
  3. Denoise: 0.5, Mask Strength: 0.9
  4. Output: Clean, flaw-free landscape photo

Part 7: Diffusers API Code

Inpainting

from diffusers import ErnieImageInpaintPipeline
import torch

pipe = ErnieImageInpaintPipeline.from_pretrained(
"baidu/ERNIE-Image", torch_dtype=torch.float16
)
pipe = pipe.to("cuda")

result = pipe(
prompt="clean, professional, high quality",
image=original_image,
mask_image=mask_image,
num_inference_steps=25,
strength=0.75,
guidance_scale=6.0
)

Outpainting

from diffusers import ErnieImagePipeline

pipe = ErnieImagePipeline.from_pretrained(
"baidu/ERNIE-Image-Turbo", torch_dtype=torch.float16
)
pipe = pipe.to("cuda")

result = pipe(
prompt="extended background, panoramic, seamless",
image=padded_image,
mask_image=outpaint_mask,
num_inference_steps=8, # Turbo mode
guidance_scale=5.0
)


Part 8: Troubleshooting

Q1: Repaired area doesn't blend with original

Symptoms: Visible boundary line or color mismatch at the repair area.

Solutions:

  1. Increase Mask Blur (8-12) for smoother transitions
  2. Reduce Denoise (0.3-0.5) to minimize changes
  3. Shrink mask area to only cover what needs modification
  4. Add seamless, natural transition, matching colors to prompt

Q2: Expanded area style inconsistency

Symptoms: Extended area differs in style or tone from the original.

Solutions:

  1. Describe original image in detail for sufficient context
  2. Reduce Denoise (0.5-0.6) to maintain original style
  3. Step-wise expansion (20%-30% per step, not 100% at once)
  4. Increase CFG (6.0-7.0) in Turbo mode

Q3: Black lines or white edges at mask boundary

Symptoms: Abnormal lines at the repair/expansion edge.

Solutions:

  1. Use Gaussian blurred mask (Mask Blur: 4-8)
  2. Add seamless, no borders, natural edges to prompt
  3. Reduce Inpaint Strength (0.7-0.8)
  4. Ensure mask resolution matches original image

Q4: Inaccurate text rendering

Solutions:

  1. Turn off PE (most important!)
  2. Use standard mode (not Turbo) — 50 inference steps
  3. Describe text precisely, use quotes
  4. Reference the ERNIE-Image text rendering guide

Part 9: Summary — When to Use Inpainting vs Outpainting

Need Recommended Key Parameters
Remove strangers/watermarks Inpainting Denoise 0.5, Mask Blur 6
Background replacement Inpainting Denoise 0.7, CFG 6.0
Add objects Inpainting Denoise 0.8, CFG 7.0
Canvas expansion Outpainting Expand 30%, Denoise 0.6
Full-body completion Outpainting Expand 50%, Steps 25
Style conversion Inpainting Denoise 0.9, CFG 8.0

ERNIE-Image Inpainting/Outpainting core advantages:

  1. Precise control: Pixel-level mask specification for repair/expansion areas
  2. Context-aware: Automatically understands image style, tone, and composition
  3. Seamless blending: Repaired areas integrate naturally with no visible boundaries
  4. Flexible application: From flaw repair to creative expansion — covers 90% of image editing needs
  5. Turbo acceleration: 8-step fast generation for batch processing

For photographers, designers, and ecommerce operators, this is the core "re-creation" tool. One source image can spawn dozens of variations through Inpainting + Outpainting, dramatically reducing production costs.


This workflow uses ComfyUI + ERNIE-Image 8B. Code examples use Diffusers API.

ERNIE-Image Team