Skip to content
mentoor

Topic 2 of 6 · 4 min read

Editing images with masks and reference images

Goal: Write an edit request with the right mask and reference images so only the intended region of a product photo changes.

An edit request has three jobs: say which pixels may change (the mask), say what to change them into (the instruction), and say what must stay the same (the reference images and the constraints).

Check yourself · 1 of 3

You want a new background behind a product and the product left alone. What should the mask cover?

Choose one answer

Why it matters

Product teams rarely need a new picture. They need the same bottle on a beach instead of a white table, or the same jacket in another colour. If the model redraws the whole image, the logo warps, the label text changes and the face of a model becomes someone else. Editing APIs exist to limit the change.

How to do it

  1. Pick the edit style. Inpainting takes the source image, a mask and a prompt; only the masked area is regenerated. Conversational editing, as in Gemini image models and the OpenAI image endpoints, takes the source and an instruction in plain words, and the model decides what to touch.
  2. Make the mask match the intent. Cover the background, not the product. Add a small margin so edges blend. Check how the provider reads the mask: some treat transparent pixels as the area to edit, others use a separate mask image, so read the docs and test with one image.
  3. Pass reference images for identity. To keep a product, character or brand look the same across shots, send the original photo or a few angles as references and say so: "Keep the bottle and its label exactly as in the reference image."
  4. State what must not change. Name faces, logos and printed text in the instruction. Text and small logos are where models fail most.
  5. Edit in small steps and compare. One change per request. Keep the original; every edit is a new file, never an overwrite.
  6. Check the result. Compare the protected region of the output with the original, by eye for a first version and by a pixel difference or a logo-matching check at scale.

Before and after

Before: "Make this photo look better and put it outside." with the full image, no mask.

The model may restyle the bottle, redraw the label and change the lighting on the product.

After: Source photo of the bottle, a mask covering only the white table and wall, and the instruction: "Replace the masked background with a sunny beach at golden hour. Keep the bottle, its label text and its shadow shape unchanged."

What goes wrong

  • The mask is the wrong way round, so the product is repainted and the background stays.
  • A mask with a hard edge leaves a visible halo around the product.
  • The label text comes back with new, slightly wrong letters, and nobody checks.
  • Several changes in one request: colour, background and pose. One of them is silently dropped.

Examples

Background swap on a product shot

Source: bottle.png. Mask: white table and wall selected, bottle excluded, with a few pixels of margin.

Instruction: "Replace the masked area with a wooden kitchen counter in morning light. Do not change the bottle, the label or the cap."

Same character, new scene

Send three reference images of a mascot and ask: "Draw this mascot waving at a train station. Match the colours, outline weight and proportions of the references." Then compare against the references before publishing.

Key points

  • An edit request defines what may change (mask), what to change it into, and what must stay.
  • Inpainting regenerates only the masked area; conversational edits leave the choice of area to the model.
  • Check how each provider reads the mask before relying on it; test with one image.
  • Reference images and explicit text about logos, faces and printed text help keep identity stable.
  • One change per request, original kept, protected region compared with the output.

Common mistakes

  • Sending an edit with no mask and expecting only the named object to change.
  • Masking the product instead of the background, or inverting the mask the provider expects.
  • Asking for several changes in one request and not checking which ones were applied.
  • Trusting regenerated text or logos without comparing them with the original.

Check yourself · 2 of 3

After an edit, the label on a bottle reads "ORGANlC" instead of "ORGANIC". What is the most reliable fix?

Choose one answer

Check yourself · 3 of 3

Why send reference images when asking for the same mascot in a new scene?

Choose one answer

Practice items, not counted towards your mastery.

Start here

Where to go in your country