Sub topic 7
Guiding results with reference images and edits
Text prompts describe what you want, but they are imprecise about layout, proportions, and exact looks. Reference images and edits let you show the tool what you mean and change only the part that is wrong. This chapter covers the three main techniques: image-to-image generation, inpainting, and style or subject references. It also covers how to choose between them and how they fail.
It assumes you have written a creative brief, can build a structured prompt, and iterate one change at a time, as covered in earlier chapters. You should also know what resolution and aspect ratio mean. The code example uses Python with Pillow.
Why prompts alone are not enough
A prompt such as "bottle on the right third, empty space on the left" is a request, not a guarantee. The tool may place the bottle at the center in one run and the right in the next. Three situations push you toward references and edits:
- You have a layout, sketch, or earlier approved image that the result must follow.
- You like 90% of an image and want to fix one region, such as a hand, a background object, or a patch of sky.
- You need a look that is hard to put into words, such as a specific photographic style or a product shape.
Each technique gives up some freedom in exchange for control. Choose the one that gives just enough control for the job.
The three techniques
| Technique | You provide | The tool does | Best for | Main risk |
|---|---|---|---|---|
| Image-to-image | A source image plus a prompt and a strength setting | Starts from your image, adds noise, and redraws it | Restyling, matching a layout, turning a rough mock-up into a finished image | Strength set too high loses the layout, too low changes nothing |
| Inpainting | An image, a mask marking the region, and a prompt | Regenerates only the masked region | Fixing defects, swapping a background object, making room for a headline | Visible seams where the edit meets the original |
| Reference guidance | One or more reference images, with a prompt | Borrows style, color, or subject traits from the references | Matching a campaign look, keeping a character or product similar | Tools interpret references loosely, and the product may drift |
Some tools also offer outpainting, which extends the canvas beyond the original edges. It works like inpainting, with the new area as the masked region. It is useful for turning a square image into a wide banner. Check the result carefully, because the tool has to invent content that never existed.
Image-to-image and the strength setting
In image-to-image generation, the tool does not start from random noise. It starts from your image with some noise added, then denoises it toward your prompt. The strength (also called denoising strength or image influence, depending on the tool) controls how much noise is added.
- Low strength (roughly 0.2 to 0.4): the result stays close to the source. Colors and finish change, but shapes stay.
- Medium strength (roughly 0.4 to 0.7): composition holds, but details are redrawn. This is the usual range for turning a sketch into a polished image.
- High strength (above 0.7): the source barely constrains the result.
Scales differ between tools. Some use 0 to 1, others 0 to 100, and some invert the meaning so a higher number means more fidelity to the source. Read the tool's documentation, then test three values on the same source before relying on a number.
A useful source can be very rough. A layout mock-up made of colored rectangles (a blue block for the headline area, a gray block for the product position) often works well, because it fixes composition without fixing detail. Keep the prompt consistent with the source. If the source shows a bottle on the right and your prompt says "bottle on the left", the two will fight.
Follow the same rule as in the iteration chapter: change one thing per run. Change the strength or the prompt, not both.
Inpainting step by step
Inpainting regenerates only the area you mark. The mask is a black and white image the same size as the source. In the most common convention, white marks the area to change and black marks the area to keep. Some tools use transparency instead, or reverse the colors, so check which one yours uses.
The script below builds a feathered mask for a rectangular region. Feathering blurs the mask edge slightly, which helps the new content blend with the old.
from pathlib import Path
from PIL import Image, ImageDraw, ImageFilter
def make_mask(image_path, box, out_path, feather=8):
"""Write a mask where white is the region the tool may change.
box is (left, top, right, bottom) in pixels of the source image.
"""
with Image.open(image_path) as img:
size = img.size
mask = Image.new("L", size, 0) # black: keep everything
draw = ImageDraw.Draw(mask)
draw.rectangle(box, fill=255) # white: allow changes here
if feather > 0:
mask = mask.filter(ImageFilter.GaussianBlur(feather))
mask.save(out_path)
return mask
if __name__ == "__main__":
Path("work").mkdir(exist_ok=True)
# Stand-in for a generated hero image, so the script runs as shown.
Image.new("RGB", (1080, 1350), "gray").save("work/hero.png")
make_mask("work/hero.png", (0, 0, 1080, 300), "work/mask_top.png")
print("Mask written to work/mask_top.png")Use the real hero image and your own box in place of the stand-in. Then upload both files to the tool and write a prompt that describes only what should appear inside the masked area, for example "smooth pale morning sky, no objects". Do not re-describe the whole image.
Tips that prevent most inpainting problems:
- Make the mask slightly larger than the defect. A tight mask leaves a halo of the old content.
- Match the lighting words in your prompt to the surrounding image. "Soft morning light from the left" keeps shadows consistent.
- Run several candidates and pick the best seam. Edits vary more between runs than full generations do.
- Keep the source resolution. If the tool downsizes the image to edit it, the edited region may look softer than the rest.
Reference images for style and subject
Reference guidance feeds one or more images into the generation as examples. Tools use them in different ways:
- Style reference: copies color, texture, and mood but not the content.
- Subject or character reference: tries to keep a person, product, or object recognizable in a new scene.
- Structure reference: follows edges, pose, or depth from the reference, such as a sketch or a photo's outline.
A good reference set is small and consistent. Two or three images that share one look guide better than ten images that disagree. Crop references to what matters: if you want the lighting of a photo, a crop without distracting objects keeps the tool from copying them.
Reference guidance is approximate. A product reference may keep the bottle's general shape while changing the cap, label, or proportions. For products where the exact shape matters, a better route is to photograph the real product and use it as the base, then generate or edit the surroundings. Treat any generated version of a real product as a likeness that must be checked against the real item, because an inaccurate depiction can mislead customers.
Common failure modes
- Ghosting from a source image: the result keeps unwanted objects from the source. Lower the strength or mask them for removal.
- Style bleed: a reference brings in its content, not just its look. Use a tighter crop or a different reference.
- Visible seams: the edited patch has a different grain, color, or sharpness. Enlarge and feather the mask, then match lighting in the prompt.
- Drifting identity: a character or product changes between images. Use the same reference every time, and keep a record of which one you used.
- Wrong mask polarity: the tool changes everything except the region you marked. Test on a throwaway image first.
- Unrecorded settings: you cannot reproduce a good result later. Log the source file, mask, strength, prompt, and any seed value for each run.
A practical workflow
- Generate a base image from your brief.
- Decide whether to accept it, fix a region, or restyle it.
- For a fix, build a mask and run inpainting with a prompt for the masked area only.
- For a restyle, run image-to-image at three strengths and compare.
- Save the approved version and note the settings.
- Reuse the approved image as a reference for the next asset in the campaign.
Step 6 connects to the next chapter. A small set of approved images, used consistently as references, is a main tool for keeping a campaign on brand.
Exercise
You generated a hero image of a running shoe on a trail. The shoe and background are good, but the sky has a smudgy object where you want empty space for a headline. Which technique do you use, and what two things do you do to the mask and prompt?
Show answer
Use inpainting. Make the mask slightly larger than the smudge and feather its edge, so the new sky blends with the old. Write a prompt that describes only the masked area, such as "clear pale morning sky, no objects", with lighting that matches the rest of the image. Run several candidates and pick the one with the cleanest seam.
Exercise
You run image-to-image on a rough layout mock-up and the result ignores your composition completely. What setting do you adjust first, and how do you test the change?
Show answer
Lower the strength (or raise the image influence, depending on the tool's scale) so the source constrains the result more. Test by running the same source and prompt at three different strength values, changing nothing else, and compare how well each keeps the layout.