Computer vision
Image Generation, Editing, and Diffusion
Understand generative objectives, latent diffusion, conditioning, guidance, editing, evaluation, and responsible product design.
By the end you can
- Describe the training and sampling intuition behind diffusion image models
- Distinguish generation, reconstruction, editing, and restoration
- Explain conditioning, guidance, and latent-space tradeoffs
- Evaluate synthetic images for prompt fidelity, diversity, memorization, and provenance
Generation begins with a distribution, not a single correct image
A prompt such as “a red bicycle beside a canal” admits many valid scenes. Evaluation therefore has to separate prompt adherence, visual quality, diversity, consistency, and prohibited content. Those are not one axis under several names. Later in this lesson an automated image score and 1,633 blinded human comparisons rank the same two models in opposite directions. That is what it looks like when the axes are collapsed into one number.
Editing adds another constraint. Preserve specified parts of the source while changing others. That is a different contract from unconstrained generation. And in at least one published editor it is not one setting but two: a scale for how much of the input survives, and a scale for how hard the instruction is applied.
A generative system is evaluated over sets of possible outputs and product constraints.
Visual
Noise prediction connects training to iterative sampling
A simplified diffusion pipeline learns how to reverse controlled corruption. Draw a clean image from the training distribution. Corrupt it at a chosen step according to a known schedule. Train the network to predict the noise, or a related target, from the noisy image, the timestep and the conditioning. At inference there is no target image to start from, only noise, and a scheduler applies the conditional predictions repeatedly until an image emerges.
Latent diffusion moved that loop off the pixels. Rombach and four colleagues run the noising and the denoising “in the latent space of powerful pretrained autoencoders”. The point of doing so is cost. It is how you “enable DM training on limited computational resources while retaining their quality and flexibility”. Conditioning enters through attention. “by introducing cross-attention layers into the model architecture”, they write, the same models become “generators for general conditioning inputs such as text or bounding boxes”. That was 2022. Text-to-image as most people have met it starts there.
Guidance has authors too. Ho and Salimans jointly train “a conditional and an unconditional diffusion model” — “We use a single neural network to parameterize both models” — and then combine “the resulting conditional and unconditional score estimates to attain a trade-off between sample quality and diversity similar to that obtained using classifier guidance”. Trade-off is the authors' own word. Nobody described it as free.
1. Sample a clean image
Draw an image from the training distribution.
2. Add noise at a chosen step
Corrupt the image according to a known schedule.
3. Predict noise or a related target
Train the network using the noisy image, timestep, and conditioning.
4. Start from noise at inference
Initialize a sample without a target image.
5. Iterate the reverse process
Apply a scheduler and conditional predictions until an image emerges.
Comparison
Generation, reconstruction, restoration, and editing
Similar-looking outputs can make different claims about their relationship to source evidence, and the claim decides which tests are meaningful.
Unconditional or prompted generation creates a new sample from learned distributions. There is no single target image, so diversity and prompt fidelity are the things worth measuring. Concept art is the ordinary case.
Reconstruction or restoration estimates a latent source from a measurement. Fidelity to the evidence is the point, the forward model matters, and invented detail is a failure rather than a feature. Denoising is the ordinary case.
Editing modifies selected attributes while preserving protected content. Consistency with the source is the contract, masks or instructions define the scope of the change, and identity drift is the characteristic failure. A product mockup is the ordinary case.
The pixels do not tell you which of the three you are looking at. The same output can be excellent under one contract and a defect under another.
Unconditional or prompted generation
Create a new sample from learned distributions.
- No single target image
- Diversity matters
- Prompt fidelity matters
- Example: concept art
Reconstruction or restoration
Estimate a latent source from a measurement.
- Evidence fidelity matters
- Forward model matters
- Hallucination risk
- Example: denoising
Editing
Modify selected attributes while preserving protected content.
- Source consistency matters
- Masks or instructions define scope
- Identity drift possible
- Example: product mockup
Analogy
Developing a scene through repeated correction
An illustrator begins with television static and adjusts it repeatedly toward a written brief. Each pass removes some inconsistency while preserving randomness that allows different outcomes.
The analogy breaks in one place. An illustrator consciously checks the brief on each pass; the model follows a learned probabilistic field. What the static conveys is iterative refinement from noise.
Sampling is a controlled stochastic trajectory, not retrieval of one stored picture.
Key idea
Stronger guidance can narrow variety and amplify artifacts
Classifier-free guidance pushes the sample toward the conditioning signal. Higher guidance often improves prompt salience up to a point. Past that point it narrows diversity, or produces oversaturated and brittle images.
The team that hit that wall measured it, named it and explained it. Imagen's fourteen authors write that “increasing the classifier-free guidance weight improves image-text alignment, but damages image fidelity producing highly saturated and unnatural images”. Their diagnosis is a train-test mismatch: high weights push the x-prediction outside the [-1, 1] range the model saw during training. Their fix is not a smaller weight. It is a correction inside the sampler — static and dynamic thresholding — and they report that dynamic thresholding gives significantly better photorealism and text alignment, especially at very large guidance weights.
So treat guidance scale as a product parameter with slice-specific evaluation, not as a universal quality knob. If a large weight is required, the sampler has to be built for it.
More conditioning pressure is not monotonically better.
Example
Editing controls define what the system is allowed to change
A trustworthy editor shows and tests the constraints on what must be preserved. Two published systems make those constraints concrete.
ControlNet adds spatial conditioning to a locked, pretrained Stable Diffusion backbone. The new path is wired in with zero-initialized convolution layers — 'zero convolutions' — so that no harmful noise reaches the finetuning. Edges, depth, segmentation and human pose are the conditions its authors test. On how much data this takes they are explicit: “We show that the training of ControlNets is robust with small (<50k) and large (>1m) datasets.”
Instruction editing needed a dataset that did not exist, so InstructPix2Pix built one. Its authors hand-wrote instructions for 700 input captions sampled from LAION-Aesthetics V2 6.5+, fine-tuned GPT-3 Davinci on them for one epoch, and generated a final corpus of 454,445 instruction-and-caption examples. At sampling time the model then exposes two classifier-free guidance scales instead of one: “Increasing sI results in edited images that more closely resemble the input image, and increasing sT results in more intense edits.” Preservation and change are literally two dials. An editing product is a decision about where they are set.
- Mask-based inpainting: Modify only a selected spatial region, so untouched pixels are preserved by construction rather than by hope.
- Outpainting: Extend beyond the original frame while preserving the interior.
- Structure conditioning: Use depth, edges, pose, or segmentation to guide composition — ControlNet is the named architecture, a frozen backbone plus zero convolutions, reported robust from under 50,000 to over 1 million training examples.
- Reference conditioning: Transfer style or identity cues from another image.
- Instruction editing: Interpret a natural-language change request — InstructPix2Pix learned this from 454,445 generated instruction-and-caption examples seeded by 700 hand-written ones, and gives the user separate scales for input similarity and edit strength.
- Identity preservation: Measure whether protected faces, products, or logos remain stable — leaked marks are the failure mode a court has already ruled on.
Steps
Evaluate a generative image product as a system
Offline image scores are one layer of evidence, and there is a published case of the score and the raters pointing in opposite directions. In 2024 Google Research put a full Muse model against a deliberately early-stopped one, over all 1,633 PartiPrompts, blinded, three independent raters per pair. The full model is Model-A. “We observed that Model-A was preferred in 92.5% of the comparisons, while Model-B was preferred only 6.9% of the time.” The raters were not hesitating: 0.6% were indifferent, and Cohen's kappa was 0.9937.
FID ranked the pair the other way round, 18.42 for the degraded model against 21.40 for the full one. So did FID-infinity, 17.19 against 20.16, and KID, 0.0080 against 0.0105. The authors' proposed CMMD agreed with the raters, 0.721 against 0.951, lower being better. Their own preprint states it plainly: “We empirically demonstrate that FID contradicts human raters”.
A memorization probe returns numbers too, and they are small without being zero. Somepalli and four colleagues searched 12 million LAION-Aesthetics v2 6+ images against Stable Diffusion outputs with an SSCD retrieval model. Generations exceeding 0.5 similarity to a training image came to roughly 170 images, about 1.88% of the random generations. The training images matched above that threshold had themselves been duplicated an average of 34.1 times. Then comes the caveat a product team has to carry: the searched set is less than 0.6% of the model's training data, so this is a lower bound obtained on a sliver. “While most of the generations from large-scale models do not contain copied content, a non-trivial amount of copying does occur”.
Around those two measurements sits the rest of the loop. Build prompt suites covering objects, attributes, counts, relations, rendered text, cultures and prohibited requests. Measure fidelity and diversity with automated scores and blinded human comparisons, knowing from the Muse comparison that the two can invert. For editing, quantify protected regions, identity, geometry and unintended change. Probe memorization with a retrieval model, and report what fraction of the corpus you actually searched. Then monitor the product itself: rejection, complaints, provenance, unsafe outputs and distribution shift.
1. Build prompt suites
Cover objects, attributes, counts, relations, text, cultures, and prohibited requests.
2. Measure fidelity and diversity
Combine automated measures with blinded human comparisons.
3. Test preservation
For editing, quantify protected regions, identity, geometry, and unintended changes.
4. Probe memorization
Search for near-duplicates and exposure of sensitive or copyrighted examples.
5. Monitor product behavior
Track rejection, complaints, provenance, unsafe outputs, and distribution changes.
Key idea
Provenance helps establish history, not semantic truth
Content credentials can record that an image was created or edited by a particular tool under a signed process. The metadata may still be stripped, and provenance does not prove the depicted event occurred. The specification says as much about itself. The C2PA technical specification states that “C2PA specifications SHOULD NOT provide value judgments about whether a given set of provenance data is ‘good’ or ‘bad,’ merely whether the assertions included within can be validated as associated with the underlying asset, correctly formed, and free from tampering”. It also records that “an asset can become separated from its C2PA Manifest due to removal or corruption of asset metadata”.
Government agencies say the reader-facing half out loud. A joint cybersecurity information sheet on Content Credentials from the NSA and three partner agencies, published in January 2025, states that “this metadata alone does not allow a consumer to determine whether a piece of content is “true,” but rather provides contextual information that assists in determining the authenticity of the content”. The same advisory warns that “lack of provenance information should not automatically make media less trustworthy”. A credential is not proof. Its absence is not proof either.
Memorization is the other half of an origin claim. Carlini and eight colleagues report that “with a generate-and-filter pipeline, we extract over a thousand training examples from state-of-the-art models, ranging from photographs of individual people to trademarked company logos”, and conclude that “diffusion models are much less private than prior generative models such as GANs”.
A court has now ruled on both halves for a named model. On 4 November 2025 the High Court of England and Wales handed down judgment in Getty Images v Stability AI. The secondary copyright claim was dismissed: Stable Diffusion “does not store or reproduce any Copyright Works”, and so is not an infringing copy under sections 22 and 23 CDPA. Getty succeeded only on narrow trade mark grounds, sections 10(1) and 10(2), because early model versions generated Getty Images and iStock watermarks in their outputs; the section 10(3) claim was dismissed. “In summary, although Getty Images succeed (in part) in their Trade Mark Infringement Claim, my findings are both historic and extremely limited in scope. The Secondary Infringement Claim fails.” — Mrs Justice Joanna Smith. What leaked into the outputs was actionable. The weights were held not to hold the works.
Marking, meanwhile, has stopped being a matter of product taste in one large market. Article 50(2) of the EU Artificial Intelligence Act, adopted 13 June 2024, reads: “Providers of AI systems, including general-purpose AI systems, generating synthetic audio, image, video or text content, shall ensure that the outputs of the AI system are marked in a machine-readable format and detectable as artificially generated or manipulated.” Article 50(4) separately requires deployers to disclose deep fakes. The obligation applies from 2 August 2026.
Origin records and truth claims answer different questions.
Example
Practice: design a product-image editor
A retailer wants to change backgrounds and lighting while preserving the exact product shape, label, and color. Every choice below is a place where one of the results above lands on the specification.
- Define protected attributes and measurable tolerances: product geometry, label text, logo and color, each with a number attached rather than a description.
- Choose masks or structural controls that limit the editable region — depth, edge, pose or segmentation conditioning of the ControlNet kind holds the composition while the surroundings change.
- Create tests for label corruption, logo drift, and color shift; if you expose an instruction editor, separate the input-similarity scale from the edit-strength scale as InstructPix2Pix does, instead of shipping one blended strength slider.
- Specify how generated assets receive provenance metadata, and decide whether your edits fall inside the Article 50(2) exception, which “shall not apply to the extent the AI systems perform an assistive function for standard editing or do not substantially alter the input data” — swapping an entire background is not obviously standard editing, and the obligation applies from 2 August 2026.
- Add a human review rule for regulated or safety-critical products, and treat a leaked mark — the Getty Images and iStock watermarks that decided the trade mark half of the Getty judgment — as a blocking defect rather than a cosmetic one.
Key takeaways
- Diffusion models learn to reverse controlled corruption and sample through an iterative stochastic process; latent diffusion runs that loop “in the latent space of powerful pretrained autoencoders” and carries conditioning through cross-attention.
- Generation, restoration, reconstruction, and editing make different claims about source fidelity, so the same output can be excellent under one contract and a defect under another.
- Guidance is a trade-off named by its own authors: Imagen reports that raising the weight “damages image fidelity producing highly saturated and unnatural images”, because predictions leave the [-1, 1] range seen in training.
- Editing systems need explicit preservation constraints and tests for unintended change — InstructPix2Pix splits preservation and change into two separate guidance scales, and ControlNet fixes structure with a frozen backbone plus zero convolutions.
- Automated image scores can invert human judgement: FID preferred the Muse model that 1,633 blinded comparisons rejected 92.5% to 6.9%, so prompt suites, human comparisons, memorization probes (roughly 170 generations, about 1.88%, above 0.5 similarity) and production monitoring are all separate layers of evidence.
- Provenance records creation history but does not prove the truth of depicted content; the C2PA specification and the January 2025 advisory from the NSA and its three partner agencies both say so, and from 2 August 2026 Article 50(2) of the EU AI Act makes machine-readable marking of synthetic images a legal obligation.