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.
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
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.
- 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 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?
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.
- 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.
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
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.
- When is it a good idea to use lossless compression?
- When should you use lossy compression?
- What are the important factors in making that decision?
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)
- 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.
Assessment: Check for Understanding
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?
- 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