# Image Generation with Checks

Course: [Multimodal AI](https://www.devtutorials.ai/learn/multimodal-ai) · Section: Listening, Speaking and Generating
Source: https://www.devtutorials.ai/learn/multimodal-ai/listening-and-generating/image-generation

> Run an image studio: write the prompt, choose a model, generate candidates, check them, repair small flaws with edits, get a person's approval and attach a C2PA label.

## What Image Generation Is

**Image generation** = a model that makes a new picture from a written description, called a **prompt**.

In this lesson, you will run an **image studio** for the claims app: product banners for help pages and customer emails. You write the prompt, choose a model, generate a few candidates, check each one, fix small flaws, get a person's approval and label the result.

The first version does none of that. One brief asks for a parcel box with the words "Free returns". The first image looks lovely. The words on it are misspelt, and it goes out in thousands of customer emails.

Press **Play**, or use **Next** to go one step at a time.

- **Frame 1:** the brief, as a list of things you can test.
- **Frame 2:** the image that was sent, with the wrong words.
- **Frame 3:** OCR reads the words and rejects it; another candidate passes.

**Simple lesson:** a generated image is a guess. Ask well, then check before anyone sees it.

### A Real-World Example

Think about a print shop making a shop sign.

- The customer gives a written order: the words, the colours, the size. The shop also asks for a photo of the shop front.
- The designer makes a few drafts.
- Someone checks each draft against the order, letter by letter.
- A draft that is nearly right is touched up, not thrown away.
- The customer signs it off, and the invoice says who made it and when.

Your image studio does the same:

- **The written order** = the prompt and the negative prompt.
- **The photo of the shop front** = a reference image of the real product.
- **A few drafts** = several candidates, from a seed.
- **Checks** = an object detector, a colour count, OCR on the words, the shape, safety.
- **Touch up** = an edit: inpaint, recolour, outpaint, or a text layer.
- **Sign-off** = a person approves; a C2PA label records how it was made.

**Simple lesson:** prompt, generate, check, edit, approve, label.

## What You Will Learn

By the end of this lesson, you will be able to:

- turn a brief into a prompt and a negative prompt
- choose an image model by cost, speed, size and how well it draws words
- use a reference image and a text layer
- check each candidate with other models
- repair one flaw with an edit instead of generating again
- add human approval and a C2PA provenance label

## Step 1: Write the Prompt

A **prompt** says what you want. A **negative prompt** says what you do not want. The **seed** fixes the random start, so the same prompt and seed give the same image again.

Step through all five frames.

- **A one-line prompt:** almost every candidate has a flaw.
- **Objects and colours named:** fewer flaws.
- **Size and a negative prompt** ("people, logos, watermarks"): fewer again.
- **Words as a text layer:** spelling flaws disappear.
- **A reference photo:** the product looks like the real one.

| Prompt part | Example | Prevents |
|---|---|---|
| Subject and objects | "the KettleMax on a worktop" | A missing product |
| Colours | "only sand, teal and white" | Off-brand colours |
| Size | 1792×1024 for a wide banner | The wrong shape |
| Negative prompt | "people, faces, logos, watermarks" | Strangers and other brands |
| Reference image | the real product photo | A kettle that is not yours |

**Do not ask an image model to spell.** Most image models still get words wrong some of the time. Ask for clear space instead, then add the words as a text layer in your app. The font, the spelling and the translation are then always right.

**Simple lesson:** say what you want, what you do not want, and show the real product.

## Step 2: Choose the Model

Step through the frames.

- **Hosted, high quality:** the best pictures, but 24 candidates cost more than the $1.00 budget.
- **Hosted, fast:** cheap and quick. Checks and edits make up for the extra flaws.
- **On the device:** free and private, but 512 px. It fails until you upscale to 1024 px.

| Model | Cost per image | Time | Size | Words right |
|---|---|---|---|---|
| Hosted, high quality (e.g. gpt-image-1, Imagen 4) | about $0.04 | about 9 s | 1024 px | most of the time |
| Hosted, fast (e.g. FLUX schnell) | about $0.01 | about 2 s | 1024 px | about half |
| On the device (e.g. SD-Turbo, WebGPU) | free | about 5 s | 512 px | rarely |

Prices here are illustrative. Check your provider's current prices, and open the **Settings** tab to see whether your machine can run SD-Turbo.

## Step 3: Check, Then Edit

Every candidate goes through five checks, using other models: objects (a detector), colours, words (OCR), shape, and safety (people and logos).

Step through all five frames.

- **The row of checks:** added one at a time.
- **The gauge:** how many images are judged right.

When a good image has exactly **one** flaw, fix that part instead of generating again.

Step through both frames.

- **No edits:** one brief has no usable image.
- **With edits:** a few cheap edits cover every brief.

| Flaw | Edit |
|---|---|
| A missing object, a stranger, another logo | **Inpaint**: redraw just that area |
| A colour off the palette | **Recolour** |
| The wrong shape | **Outpaint**: extend the picture |
| Wrong words | Replace them with a **text layer** |

**Never publish a generated image without a person's approval.** Checks catch known flaws. A person catches the rest: a face that looks like a real customer, a product shown doing something unsafe, a picture that is just wrong for the brand.

## Step 4: Label It

**Provenance** = a record of where an image came from. **C2PA** is the open standard for it (shown to people as Content Credentials). The manifest says the image was made by an AI model, lists each edit, and who approved it.

Step through both frames.

- **Frame 1:** an image with no label. A customer asks if the photo is real.
- **Frame 2:** the label, in the image's metadata.

**Easy way to remember:** ask well, check everything, fix small, approve, label.

Click the button and look at the **Pipeline** tab.

- **The prompt box:** the exact prompt, negative prompt, size and seed your settings build.
- **The grid:** each candidate, drawn from the seed bank, with what the checks found.
- **Show manifest:** the C2PA-style record for an accepted image.

### Lab Exercise: Ship Six On-Brief Images

Your task: set up every stage of the studio, then press **Check**.

Click the button and open the **Pipeline** tab.

- **Ingest:** the reference photo.
- **Perceive:** the model, candidates per brief, and the seed.
- **Structure:** the prompt parts and the text layer.
- **Verify, Route, Use:** checks, edits, approval, upscaling and the label.
- **To pass:** a usable 1024 px image for all 6 briefs, no flawed image accepted, under $1.00, approved and labelled.

## Build It in TypeScript

`judge()` returns the reasons a candidate fails. No reasons: accept it. The candidate is what the detectors and OCR found in the image.

```ts
export function judge({ c, brief }: { c: Candidate; brief: Brief }): Verdict {
  const reasons: string[] = [];
  if (!brief.must.every((e) => c.elements.includes(e))) reasons.push("object");      // on brief
  if (!c.colors.every((x) => brief.palette.includes(x))) reasons.push("palette");
  if ((c.caption ?? "") !== (brief.caption ?? "")) reasons.push("text");             // OCR of the words
  if (c.aspect !== brief.aspect) reasons.push("aspect");
  if (c.elements.includes("person")) reasons.push("person");                         // safety
  if (c.elements.includes("logo")) reasons.push("logo");
  return { accept: reasons.length === 0, reasons };
}
```

Click the button and open the **Code** tab.

- **The starter:** accepts every image.
- **Run on the media bank:** your function judges 48 candidates.

## TL;DR

1. A **prompt** says what you want; a **negative prompt** says what you do not.
2. A **reference image** keeps your real product; a **text layer** keeps words exact.
3. Choose the **model** by cost, speed, size and spelling. Small on-device images need **upscaling**.
4. **Check** every candidate with other models.
5. **Edit** one small flaw instead of generating again.
6. A **person approves**, and a **C2PA label** records how it was made.

## Common mistakes

| Mistake | Wrong idea | Correct idea | What goes wrong |
|---|---|---|---|
| A one-line prompt | "The model knows what I mean." | Name objects, colours, size; add a negative prompt. | Almost every image is off-brief. |
| Asking the model to spell | "It can write the words." | Add words as a text layer. | "Fre returns" in customer emails. |
| No reference image | "It knows the KettleMax." | Attach the real product photo. | A kettle that is not yours. |
| Regenerating for one flaw | "Just try again." | Inpaint, recolour or outpaint. | More cost, and new flaws. |
| Publishing without approval | "The checks passed." | A person signs off. | Something the checks never test goes out. |
| No label | "Everyone knows it is AI." | Attach a C2PA manifest. | Customers feel misled. |

## Check Your Understanding

## Exercises

## What to Remember

- Ask well: prompt, negative prompt, size, reference.
- Never trust the model to spell.
- Check every candidate with other models.
- Fix small flaws with edits.
- A person approves; a label says it is generated.

## Further Reading

- [C2PA specification, by the Coalition for Content Provenance and Authenticity](https://c2pa.org/specifications/specifications/2.1/index.html): the open standard for provenance labels.
- [Content Credentials](https://contentcredentials.org/): see how provenance labels are shown to people.

Next: **Video Understanding**, where the model has to find one second that matters in a long clip.
