Seeing the big picture
About this lesson
This practical lesson sequence examines lossy and lossless techniques of data compression. Students perform comparisons of various compressions on a variety of images.
Year band: 9-10Curriculum Links Assessment
Note: Criteria are cumulative
|Quantity of knowledge||Quality of understanding|
|Image compression||No evidence of understanding||Student is able to describe the purpose of image compression||Student is able to describe one technique of compression and decompression||Student is able to describe advantages of lossy and lossless compression||Student is able to describe advantages and disadvantages of lossy and lossless compression|
|Lossy and lossless image compression||No evidence of understanding||Student can use a software tool to achieve compression of an image||Student can use a software tool to achieve both lossy and lossless compression of an image||Student is able to describe lossy and lossless compression techniques and give an example of a file format for each||Student is able to apply lossy and lossless compression to various images|
We use shortcuts all the time in daily life: a common example is in texting.
Popular abbreviations can speed up communication, and with no loss of meaning for those who are familiar with them
- Test these abbreviations on the class (show the slides one at a time).
- BTW – By the way
- B4N – Bye for now
- BCNU – Be seeing you
- BFF – Best friends forever
- FWIW – For what it’s worth
- GR8 – Great
- GTG or G2G – Good to go or Got to go
- ILY – I love you
- IMHO – In my humble opinion
- LOL – Laughing out loud or Lots of love
Alternative for Engagement and Expression: If you think students might struggle with this task, you could do (or start with) the classic ‘telephone game’, also known as ‘Chinese whispers’, with which students should be familiar.
- Conduct a class challenge to see who can use the fewest characters with no loss of meaning for the following message, achieving the greatest compression of the message:
It’s now half past eight and I’m still waiting. If you’re not here in ten minutes I’m going home. I have waited in front of the cinema for half an hour.
Alternative for Engagement and Expression: You could use an online quiz program such as Quizlet or Kahoot!. Ask students to guess the answers. Alternatively students devise their own quiz questions and answers.
- Students may be familiar with the following well-known example showing how our brains can infer missing aspects of a message to regain meaning. The first and last letters of each word are in their correct places and others are scrambled.
- Ask one person to read it aloud.
Aoccdrnig to rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit a porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe.
Refer to this article for further information.
- Ask one person to read it aloud.
As a means for Engagement and Expression: An alternative to the scrabbled message can be to focus on one word or a phrase for example using the game hangman where certain letters are missing or students have a number of guesses to work out the word or phrase.
- Direct students to this website where they can generate scrambled sentences themselves and test them out by requiring a partner to read the scrambled version aloud:
(Note: Incidentally, creating a program to perform this scrambling is an excellent coding activity in string manipulation.)
As a means for Engagement and Expression: For students who may struggle with a sentence focus on single words to start with.
- Tell students:
Some methods to compress audio and visual data use techniques that rely on the talent our brains have of being able to fill in missing data and completely reconstruct the original message.
In the case of audio files, we can choose to transmit only sampled parts of the original sound, and with image files we can choose to transmit a reduced palette of colours or a reduced resolution. Our brains fill in the missing bits. These are examples of ‘lossy’ compression.
We will be learning about lossy methods of compression, but also ‘lossless’ methods which compress data but afterwards allow it to be completely reconstructed.
Learning map and outcomes
Compression techniques are needed to reduce the size of data transmissions. This lesson examines techniques that achieve this.
One category results in a loss of data but still retains sufficient data to convey the message (such as an image, audio or video) whereas the other can restore all original data following transmission. These two approaches are known as lossy and lossless compression respectively.
Lossy image compression
- Explain that the ‘lossy’ technique involves averaging areas of colour. This works best for images with gradients of colours rather than large areas of a single colour. The human eye can imply or extrapolate the missing detail to some extent.
Lossy Photoshop activity
- Have students use the original_image provided, or ask them to select an image from the Internet, and open it using Adobe Photoshop.
- Use File > Save for Web option to examine the quality of the image and file sizes using JPEG with the 4-up tab and setting the panes using the following levels of compression:
- Original image
- JPEG Maximum quality
- JPEG High quality
- JPEG Low quality.
- Ask students to zoom in on a detail (eg the edge of a rainbow bubble) and describe the level of detail under each of the four levels of compression. The sizes of each will be listed below each image pane.
- Students create a table and record their results. Suggest they use five columns with the headings:
- Level of compression
- File size
- Download time
- Stated quality
- Personal description of loss of detail.
Students will observe that with large reductions in file size there is a loss of quality.
This compression method is called lossy.
- Compare the listed download times and use the drop-down menu to see these for different speeds of transmission.
Lossless image compression
Introduce ‘lossless’ compression as used by Portable Network Graphics (PNG). This is achieved using a combination of Huffman and LZW (the initials of the three inventors) compression algorithms and involves two steps:
- Duplicate strings of data are replaced by pointers to a single instance of the original string (LZW compression).
- New symbols replace repeated symbols based on their frequency of use. Frequently used symbols are replaced with short code and less common symbols with longer ones (Huffman compression).
- Form students into groups of 4. Have groups agree on a rule for achieving LZW style of compression (see above). Have two of the students use this method to compress the following sentence, without showing it to the other two students:
It's a fair bet that if it's fair tomorrow, then my fair haired wife and I will head to the Spring Fair, which is held in a fair sized park, in this fair city of ours and we may win a prize in a competition if everyone else plays fair. Fair enough?
- They deliver their compressed message to their other pair who try to decompress it.
As a means for Expression: An alternative task is to focus on a text with which they are more familiar. Ask them to compress one of their favourite stories such as ‘The Three Little Pigs’ (e.g. “Who can write the story in the fewest words possible?”) They could retell the story to a younger student.
- Ask if their first effort could be further shortened with another modification idea involving individual letters.
- Distribute the worksheet text supplied: Worksheet: There was an old lady
- Repeat the lossless compression activity in same groups of 4 but with roles reversed.
- Discuss why reduction in file size might be important for Internet transmission.
- Ask when certain losses of quality would be unacceptable.
- Ask which method(s) would be suitable for transmission of text-based data (ie lossless only). Why?
Lossless Photoshop activity
- Use Photoshop’s File> Save for Web option to examine the quality of the same original image choosing PNG with the 2-up tab and setting the panes as follows:
- Original image
Here the original image and the PNG-24 images will be indistinguishable. There is no loss of data as the compression method is lossless.
- Compare the file sizes using original image, JPEG and PNG-24 compression viewed in the 4-up pane.
(PNG more than halves the file size of this image but JPEG’s highest quality is still much smaller.)
- Students add a row to the table prepared for the lossy Photoshop activity, and record the results for lossless PNG compression.
- Ask students to imagine they are back in 1978 and are one of the team members: Abraham Lempel, Jacob Ziv or Terry Welch (the original inventors of LZW compression). Ask them to discuss what methods could they use to test the effectiveness of their lossy compression invention?
- Suggest they create various images in Photoshop:
- some with large areas of single colours
- others with large areas of gradient colour
- others in greyscale or black and white only.
- Students create various images in Photoshop, some with large areas of flat colours, and others with large areas of gradient colour.
- Students compare the file sizes of these using various file formats in Photoshop.
- Students devise and complete a comparison table to summarise their findings.
Have students submit a one-page report, including image screenshots, to explain and evaluate lossy and lossless image compression techniques.