Digital Information - Lesson 10: Lossy Compression

Overview

Students are introduced to lossy compression via the Lossy Text Compression widget. They apply this concept and their prior knowledge of sampling to create their own lossy compressions of image files using the Lossy Image Widget. Students then discuss several practical scenarios where they need to decide whether to use a lossy or lossless compression algorithm. The lesson ends with a discussion of the situations where lossless compression is important and the situations where lossy compression is important.

Goals

Students will be able to:

  • Examine the effects of lossy compression on text & images
  • Given a piece of media, decide whether to use lossy or lossless compression based on the needs of a situation

Purpose

After exploring lossless compression in yesterday's lesson, students are introduced to lossy compression. A theme throughout the lesson is that lossy compression can greatly reduce the file size, but it can also greatly reduce the quality and it's important to find that balance between quality and file size. The real challenge here is finding where that line is - how much can we compress but still keep it recognizable? In the final discussion, students compare lossy compression with lossless compression to see that each has value depending on the situation - lossy is useful when file size needs to be minimized, but lossless is important when its vital to be able to reconstruct the original image.

Getting Started (5 minutes)

Remarks

  • This widget claims you can keep the first letter of a word then remove all of the vowels and the result will still be readable. Let's test this out - what are some other sentences we should try with this widget?

Do This: Use the the Lossy Compression project and try out a few phrases.

Prompt: How is this widget similar to the widget we used yesterday? How is it different?

Discussion Goal

Students should identify that this widget is similar to yesterday's text compression widget because it also shortens text, but it is different in that some of the information is permanently lost when it is shortened. You can emphasize this point by supplying some carefully-chosen sample text and seeing that the results can be ambiguous:

"there are three tiers of tires at the shop"

Students may debate whether or not this really fits the definition of compression we saw yesterday, which is a great bridge to the next part of the lesson.

Activity (30 mins)

Remarks

  • Yesterday's widget was an example of lossless compression because we could always reverse the process to recreate the original. This widget is an example of lossy compression because some information gets lost, making this process not reversible. In today's lesson, we will investigate how lossy compression works with images.

The Code.org lesson plan has a visual activity here that is currently not included in this lesson plan.

Compression Decisions (10 minutes)

Prompt: Let's imagine we are trying to use this image for a particular purpose, and we need to decide how much compression we want to use. We will look at a series of scenarios and we will)vote on how much compression is appropriate.

  • Scenario 1: You are sending this as a text message to a friend but you've almost run out of data on your phone plan
  • Scenario 2: You are a crime-scene photographer and this image is part of a crime-scene photo
  • Scenario 3: This image is part of a satellite imaging assignment for the military, being used for intelligence gathering
  • Scenario 4: You are a Social Media manager posting this to an Instagram story for an event happening right now
  • Scenario 5: This image will be part of a collage where 100 copies will be stitched together to make a larger image
  • Scenario 6: You are a professional photographer submitting to a design competition where your submission will be carefully judged for color & composition
Teaching Tip

After voting, briefly discuss each scenario and come to a classroom consensus on the best option.

Note that there is not necessarily one "correct answer" to these scenarios the goal here is to weigh the pros and cons and make an informed decision.

Wrap up (5 Minutes)

Prompt

  1. When is it a good idea to use lossless compression?
  2. When should you use lossy compression?
  3. What are the important factors in making that decision?
Discussion Goal

This discussion should draw out two key points:

  • Lossless compression is useful when the accuracy of the original item is most important
  • Examples: Bank records, text files, some images
  • Lossy compression is useful when file size is a concern or when it needs to be sent in a reasonable amount of time.
  • Examples: Multimedia - especially streaming media (images, video, audio)

Remarks

  • We've seen today that lossy compression can greatly reduce file size, but can also reduce the quality of the image. Finding that balance is important, especially when the size of your file is a concern. But, if you need to recreate an exact copy of the original, then lossless compression is a better choice.

Journal

Have students take out their journals and add the definition for lossy compression.

  • Lossy Compression: A process for reducing the number of bits needed to represent something in which some information is lost or thrown away. This process is not reversible.

Assessment: Check for Understanding

For Students

Open a word doc or google doc and copy/paste the 2 following question.

Question

You've been given a new cell phone with a 2 gigabyte data plan. You plan to use your phone for text messages, images, video, and music. Which of these categories are best compressed using lossless compression? Which of these categories are best compressed using lossy compression? Why?

Standards Alignment

  • CSTA K-12 Computer Science Standards (2017): DA - Data & Analysis: 3A-DA-10 - Evaluate the tradeoffs in how data elements are organized and where data is stored.
  • CSP2021: DAT-1.D.5, DAT-1.D.6, DAT-1.D.7, DAT-1.D.8

Next Tutorial

In the next tutorial, we will discuss CSP Digital Information Lesson 11, which describes copyright and intellectual property.