← Teacher guide

Lossy or lossless

Students raise the tolerance of a lossy run-length compressor on a grey picture to see that lossy compression stores far fewer numbers but permanently changes data, and decide where lossy and lossless each belong (AC9TDI10K03 node 3).

Making data smaller · Compression · about 45 minutes · Open the student lesson

Classroom resources

Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Try 6 min · Worked example 12 min · Vary 12 min · Practise and Make 15 min

Before class

Try the Try and Make boards yourself.

The one idea: lossless gives back exactly the original; lossy discards information permanently to save more space; choose by purpose. Kit contexts for width: medical images and legal evidence (lossless), music streaming and photos online (lossy).

Simplification: real lossy formats (JPEG, MP3) don't merge nearby shades in runs; they use smarter maths to throw away what people perceive least. The board shows the same trade-off in a form students can see.

Running the lesson

  1. Predict: students who chose "yes" hold Sam's misconception; return to them after the Try.
  2. Try: ask which parts of the picture changed first, and why.
  3. Worked example: ask what a doctor or a court would say about the 16 changed pixels.
  4. Vary: debate the "worth it" question in pairs before checking.
  5. Make: compare: why is 27 the edge for this picture?

The hard part (on purpose)

Students believe lost detail can be recovered because the board can slide back to 0. Point out that the board keeps the original; a saved lossy file does not.

When students get stuck

What you will seeA question to askThe fix
A student says the detail comes back when you open the file (Sam's mistake).Where would the original shades be stored?Nowhere: they were thrown away.
A student thinks lossy is always bad.How long would a song take to stream at ten times the size?Lossy is a trade-off that suits many purposes.

Answers to the checks

  1. does it come back?: A grey photo is compressed by treating nearly equal shades as the same, so the runs get longer. Then it is opened again. Is it exactly the same as the original?
    No. Shades that were treated as the same are stored as one shade, and the original values were never saved, so nothing can put them back.
  2. Try: raise the tolerance: Raise the tolerance to 40 or more. How many numbers are stored now, and how many pixels came back different?

    At tolerance 40, 16 numbers instead of 28, but 16 of the 48 pixels came back a different shade. Compare with the original on the right.
  3. The trade-off: What makes compression **lossless**?
    Decompressing gives back exactly the original data
    Lossless means exact recovery. Lossy means some data is permanently discarded.
  4. Find the mistake: Sam explains what happens to a lossy photo. Click the line where it first goes wrong.
    line 3
    Line 3: the lost detail was never stored, so nothing can put it back. A lossy photo looks close to the original but is not the same.
  5. Which must be lossless?: Which of these must be stored **lossless**?
    A medical X-ray a doctor will use to find a fracture
    A change in a few pixels could hide or invent a detail a doctor relies on. Medical images, legal evidence, text and spreadsheets need every value exact.
  6. Back to lossless: Set the tolerance to 0. How many pixels come back different?

    None: at tolerance 0 only exact runs are merged. Lossless, 28 numbers.
  7. All the way: Push the tolerance to 128, the most. How many numbers now? Does it still look like the picture?

    12 numbers: one run for most rows. The rows are still lighter at the top and darker at the bottom, but the detail inside each row is gone.
  8. Worth it?: From tolerance 40 to 128, the numbers stored drop from 16 to 12 but 20 pixels change instead of 16. Is the extra squeeze worth it?
    It depends on what the picture is for
    Compression is a trade-off between size and quality, chosen for the purpose.
  9. Streaming: A streaming service sends music in a lossy format. Why is that a good choice?
    It is much smaller, so it plays without waiting, and most listeners can't hear what is lost
    Lossy formats like MP3 throw away sounds people hear least, making files about a tenth of the size.
  10. Formats: Which format is **lossless**?
    PNG
    PNG (and ZIP) keep every value; JPEG and MP3 are lossy.
  11. Evidence: A police photo of a number plate is saved as a heavily compressed lossy file. What could go wrong?
    Letters could blur into each other, so the evidence is unclear or misread
    Evidence needs every detail; lossy compression can change exactly the details that matter.
  12. Save again: You open a JPEG, edit it and save it as a JPEG again, many times. What happens?
    It loses a little more detail each time
    Lossy losses add up. Keep a lossless original and make lossy copies from it.
  13. Review: run-length codes: Review: what is the run-length code for white, white, white, white, black, black, black, black?
    4, 4
    4 white, 4 black.
  14. the edge of lossless: Find the largest tolerance that still gives back every pixel exactly.

    Neighbouring shades in this picture are 28 or 29 apart, so up to 27 nothing merges that shouldn't: lossless. At 28, the first shades merge and the compression becomes lossy.

Solutions

One possible solution for each task. Other correct programs are fine.

Vary: one setting at a time › Back to lossless

Open task: any program that does what the step asks.

Vary: one setting at a time › All the way

Open task: any program that does what the step asks.

Vary: one setting at a time › Worth it?

Open task: any program that does what the step asks.

Vary: one setting at a time › Streaming

Open task: any program that does what the step asks.

the edge of lossless

Open task: any program that does what the step asks.

Stretch and support

Stretch: Save a photo as JPEG at quality 100 and quality 10 and compare the sizes and what changed. Which details went first?

Support: Give the two definitions on a card: lossless = exact recovery; lossy = permanent loss for a smaller file.

Exit ticket

Give one context that needs lossless compression and one where lossy is fine, with a reason for each.

Lossless: a medical scan or spreadsheet, where every value matters. Lossy: streamed music or a shared photo, where a much smaller file matters more than tiny changes.

What each step is for

Where it leads

Builds on: Run-length encoding. Where it leads: file formats and codecs (MP3 vs WAV, JPEG vs PNG), and the ethics of altered images and evidence.