Supporting Page — Instruction Image Editing

Maskless Image Editing with Mage-Flow-Edit

Perform precise semantic adjustments, style transformations, and object replacements using natural language instructions without drawing manual binary inpainting masks.

Semantic Object Edit

Add, remove, or swap specific subjects in the scene while maintaining exact spatial backgrounds.

Instruction: "Replace the red car with a blue electric vehicle"

Style Transformation

Convert real photographs into watercolor paintings, anime sketches, or 3D claymation renders.

Instruction: "Transform scene into a cyberpunk anime drawing"

Background & Lighting Swap

Change weather, daytime illumination, or complete background environments naturally.

Instruction: "Change background to a snowy mountain peak at sunset"

1. Paradigm Shift: Instruction-Based vs Inpainting Masks

Traditional image modification pipelines rely on manual image inpainting masks. Users must carefully draw white brush strokes over target areas to indicate where diffusion models should re-sample pixels. Manual masking is tedious on mobile screens and often fails to preserve subtle light reflections, cast shadows, and edge blending.

Mage-Flow-Edit eliminates manual masking. The model processes both the original reference image latents and text instruction vectors within a unified conditioning space. The transformer dynamically identifies which image regions require semantic adjustment while keeping surrounding structural elements untouched.

2. Dual Image-and-Text Conditioning Architecture

In the Mage-Flow-Edit network, original source images are encoded via Mage-VAE into reference latent vectors z_ref. These reference latents are concatenated along the channel dimension with noisy target latents z_t:

Input Conditioning Stack:
z_concat = Concatenate(z_t, z_ref)  // Concatenated along channel axis
Text Prompt Embedding = Qwen3_Text_Encoder("instruction text")

The joint attention mechanism compares spatial features in z_ref against language tokens in the prompt. If the prompt requests "make the cat wear a wizard hat", attention weights focus specifically on the cat's head region, generating the hat while locking body posture and background furniture in place.

3. 4-Step Distilled Turbo Editing (Mage-Flow-Edit-Turbo)

Editing workflows demand instant interactive feedback. Waiting several seconds for each prompt edit degrades creative iteration. By applying consistency distillation to the editing checkpoint, Microsoft released Mage-Flow-Edit-Turbo.

Model CheckpointTarget TaskSampling StepsInference Latency (A100 GPU)
Mage-Flow-Edit-BaseInstruction Editing30 Steps~3.50 seconds
Mage-Flow-Edit (RL)Instruction Editing20 Steps~2.30 seconds
Mage-Flow-Edit-TurboInstruction Editing4 Steps1.02 seconds

4. Core Image Editing Workflow Categories

Category A: Object Insertion & Removal

Add secondary subjects into empty spaces or erase unwanted clutter. For clean removals, instruct the model explicitly: "Remove the power lines from the sky and fill with clean clouds."

Category B: Color & Material Alteration

Modify surface textures, clothing colors, or vehicle finishes without disturbing lighting reflections:"Change the jacket fabric from dark leather to bright yellow raincoat material."

Category C: Image Restoration & Quality Enhancement

Mage-Flow-Edit can upscale degraded images, denoise historical photographs, and sharpen out-of-focus subjects:"Enhance image clarity, remove grain noise, sharpen facial features."

5. Python Implementation for Automated Image Editing

The script below demonstrates how to execute batch instruction editing on local input images using PyTorch:

from PIL import Image
import torch
from diffusers import MageFlowEditPipeline

# Load source image
init_img = Image.open("living_room.jpg").convert("RGB")

# Initialize Mage-Flow-Edit-Turbo pipeline
pipe = MageFlowEditPipeline.from_pretrained(
    "microsoft/Mage-Flow-Edit-Turbo",
    torch_dtype=torch.bfloat16
).to("cuda")

# Execute instruction edit
instruction = "Add a cozy fireplace on the far wall with burning logs and warm lighting"
output_img = pipe(
    prompt=instruction,
    image=init_img,
    num_inference_steps=4,
    guidance_scale=2.0
).images[0]

output_img.save("cozy_living_room.jpg")

6. Detailed Instruction Vocabulary Matrix

Target TaskEffective Verb CommandExample Full Instruction
Object Swap"Replace [A] with [B]""Replace the wooden coffee table with a modern marble glass table"
Style Transfer"Transform into [Style]""Transform photo into a vibrant 1980s synthwave oil painting"
Attribute Change"Make [Object] [Color/Material]""Make the sports car paint brilliant crimson red with glossy reflection"
Environment Swap"Change background to [Place]""Change the background behind the person to a tropical beach at sunset"

7. Best Practices for Editing Instructions

  • Be Direct & Actionable: Use clear verbs (replace, add, change color, transform, remove) rather than descriptive paragraphs.
  • Specify What Stays Constant: If the model over-edits the background, specify: "Change the shirt color to red while preserving the background wall."
  • Keep Guidance Scale Moderate: For Mage-Flow-Edit-Turbo, set CFG between 1.5 and 2.5 to maintain smooth blending between edited objects and original surroundings.

8. Structural Preservation & Feature Locking Mechanics

Maintaining background geometry during instruction editing relies on high-level feature locking within the cross-attention blocks. When Mage-Flow-Edit processes an input image, lower-frequency spatial representations (such as camera perspective, room dimensions, horizon line, and light direction) are locked in early diffusion timesteps. Only high-frequency target tokens specified in the text instruction undergo modification in late timesteps.

9. Edge Cases & Corrective Tuning Guide

If instruction editing outputs produce unwanted background modifications or over-edited subjects, apply these tuning steps:

  • Over-editing Unrelated Areas: Decrease Guidance Scale (CFG) to 1.5 and explicitly specify preserved regions in the prompt text.
  • Under-editing Target Object: Increase Guidance Scale (CFG) to 2.5 or specify explicit object details (e.g. "Replace red shirt with vibrant cobalt blue polo shirt").
  • Fidelity Loss on Face Details: Use 20-step Mage-Flow-Edit (RL) rather than 4-step Turbo for delicate portrait facial modifications.

10. Python Batch Editing Pipeline Example

# Batch instruction editing script
instructions = [
    "Change daylight to night with shining streetlamps",
    "Add soft falling snow across the street scene",
    "Transform scene into oil painting style"
]

for idx, inst in enumerate(instructions):
    edited = pipe(prompt=inst, image=init_img, num_inference_steps=4).images[0]
    edited.save(f"edit_variant_{idx}.png")

11. Summary of Image Editing Features

Mage-Flow-Edit combines natural language instruction understanding, dual image-and-text latent conditioning, and 4-step Turbo distillation to deliver sub-second maskless image modifications across personal and commercial editing workflows. By offering precise feature preservation, custom guidance scale tuning, and batch Python script execution, our editing engine provides unconstrained creative control.