Instruction-based image editing

Also known as: InstructPix2Pix · text-guided image editing

On this page 7

Instruction-based image editing is a generative AI technique in which a model modifies an existing image according to a natural-language command, such as “replace the sky with a sunset” or “make the jacket red”, while preserving everything the instruction does not mention. Unlike text-to-image generation, which starts from noise and a full description, it treats the input picture as the primary condition and the text as a description of the change rather than of the final result.

The approach became widely known through InstructPix2Pix in 2022 and is now a standard capability of multimodal assistants and image tools. It is also called text-guided image editing, although that broader label also covers older methods that require a caption of the target image instead of an imperative instruction.

How instruction-based image editing works

An instruction-based editor is a conditional generative model that receives two inputs, the source image and the instruction, and produces an edited image. Most current systems are built on a latent diffusion model: the source image is encoded into latent space, and the denoising network is conditioned on both that latent and the text embedding of the instruction.

In the InstructPix2Pix design, the encoded source image is concatenated with the noisy latent as extra input channels, so the network can copy structure directly instead of reconstructing it from a prompt. The text instruction enters through cross-attention, the same mechanism a text-to-image model uses for prompts. Newer systems replace the U-Net with a diffusion transformer or a multimodal language model that emits image tokens, but the principle of joint conditioning stays the same.

The model learns editing from paired training examples: a source image, an instruction and the correct edited image. Because such triplets are rare in nature, they are usually synthesized at scale by combining a language model that writes instructions and edited captions with an image generator that renders before-and-after pairs. The quality of this synthetic dataset sets a hard ceiling on what the editor can learn.

The table below summarizes the main components and their role in a typical diffusion-based editor.

ComponentInputRole in the edit
Image encoderSource imageMaps pixels to a compact latent
Text encoderInstructionProduces embeddings of the requested change
Denoising networkNoisy latent plus both conditionsPredicts the edited latent step by step
Image decoderFinal latentReturns the edited image in pixel space
Guidance moduleConditional and unconditional predictionsBalances fidelity to image and instruction
Components of a diffusion-based instruction editor

Guidance scales and edit strength

Instruction editors usually expose two separate guidance scales, an extension of classifier-free guidance. The image guidance scale controls how closely the output follows the source picture, while the text guidance scale controls how strongly the instruction is applied. Tuning the two together is the main way to trade faithfulness against edit strength.

Typical starting values for InstructPix2Pix-style models are shown below; exact ranges differ between models and should be treated as starting points, not fixed rules.

ParameterTypical rangeEffect when increased
Image guidance1.0 to 2.0Output stays closer to the source image
Text guidance5 to 10Instruction is applied more strongly
Sampling steps20 to 50Finer detail, longer inference time
Random seedAny integerChanges the variant, not the intent
Output resolution512 to 1024 pxMore detail, higher memory use
Common control parameters and their effects

A high text scale with a low image scale tends to over-edit, altering faces, layouts or backgrounds that should remain untouched. The reverse setting produces under-editing, where the output looks almost identical to the input. Practitioners usually fix the seed and sweep one scale at a time.

Instruction-based editing differs from neighboring generative AI methods mainly in what the user must supply and how much of the image may change. Inpainting needs a mask, image-to-image with SDEdit needs a full target description and a denoising strength, and style transfer changes appearance globally rather than following a specific command.

MethodUser inputTypical scope of change
Instruction-based editingImage and imperative commandTargeted or global, chosen by the text
InpaintingImage, mask and promptStrictly inside the masked region
Image-to-image (SDEdit)Image, prompt and strengthGlobal, controlled by noise level
Style transferContent image and style referenceGlobal appearance, structure kept
ControlNet generationPrompt and structural mapNew image following edges or pose
Instruction editing compared with neighboring techniques

The practical advantage is no manual masking: the model infers where the change belongs from the wording. The cost is less spatial precision, so production workflows often combine an instruction with an optional mask when the edit must stay inside exact boundaries.

Types of edits and how reliably models handle them

Editing reliability depends strongly on the category of instruction. Appearance changes that keep geometry intact are the easiest, while edits that require new spatial reasoning or exact text rendering remain the most error-prone.

Edit categoryExample instructionTypical reliability
Color and materialMake the car matte blackHigh
Season or weatherTurn it into a snowy eveningHigh
Global styleRender it as a watercolorHigh
Object replacementReplace the dog with a catModerate
Object removalRemove the person on the leftModerate
Spatial rearrangementMove the lamp to the rightLow to moderate
Text in the imageChange the sign to read OpenVariable by model
Edit categories and typical reliability

Multi-step requests are usually more reliable when they are split into sequential edits, each verified before the next. Chaining many edits, however, accumulates compression and drift artifacts, so long chains should restart from a clean intermediate whenever possible.

Limitations, risks and evaluation

The most common failure is identity drift: faces, logos or fine textures change subtly even when the instruction concerns something else. Other failures include ignoring negations such as “without the hat”, confusing which of several similar objects is meant, and bias inherited from synthetic training data, which can push edits toward stereotyped appearances.

  • Ambiguous referents: “the chair” in a room with three chairs leads to unpredictable choices.
  • Counting and quantities: requests such as “add two more birds” are frequently miscounted.
  • Resolution limits: small regions in large photographs may lose detail after decoding.
  • Manipulation risk: realistic edits can support deceptive imagery, so provenance labels and content credentials are increasingly attached to outputs.

Evaluation combines automatic metrics and human judgment. CLIP-based direction similarity measures whether the change matches the instruction, while image similarity metrics on unedited areas measure preservation. Because both can be gamed, benchmark results are normally confirmed with human preference ratings.

The short version

Instruction-based image editing lets a person change a picture by typing what they want. You give the program a photo and a short request, such as “make the sky stormy”. The program changes that part. It tries to leave the rest alone.

Think of it as asking a skilled retoucher for a quick fix. You do not draw outlines or pick tools. You simply describe the change. The result is fast and often convincing. It still needs a careful look before use, because small details can shift.

Where it makes a difference

An online furniture retailer needs seasonal versions of 400 product photos for a winter campaign. Reshooting every sofa in a decorated studio would take several weeks. Instead, a small content team runs each photo through an instruction-based editor with commands such as “add warm evening light and a knitted blanket on the armrest”.

The team fixes the seed, sets image guidance near 1.5 and text guidance near 7, and checks every output against the original product. About one image in five needs a second pass because the fabric color drifted, which is unacceptable for a product listing. Those cases are corrected with a masked edit that protects the sofa itself.

The campaign assets are finished in about four working days, with every image reviewed by a person and labeled as digitally edited.