Chapter 3.3 - Representing Images

3.3. Representing Images

Time Estimate: 90 minutes

3.3.1. Introduction and Goals

In this lesson we continue the exploration of bits and binary numbers that we began in Unit 2. In this case we learn how to use bits, 1s and 0s, to represent images.

The image representation technique demonstrated in the video below is known as run-length encoding (RLE) and it is an image compressionarrow-up-right technique. Image compression is a type of data compression which can reduce the size (number of bits) of transmitted or stored data.

Learning Objectives: I will learn to

  • convert images to bits using run length encoding and text to bits using ASCII

  • describe how bits can be used to represent digital data, including images, documents, and sounds

  • understand that digital representations are an example of abstraction

Language Objectives: I will be able to

  • compare and contrast lossless and lossy compression techniques

  • use target vocabulary, such as pixel, ASCII, and run length encoding while describing how images and text are stored in memory, with the support of concept definitions and vocabulary notesarrow-up-right from this lesson

3.3.2. Learning Activities

POGIL Activity for the Classroom (30 minutes)

After watching the video above, work in POGIL teams or pairs to try your own hand at representing images using the Image Representation Activity Worksheetarrow-up-right.

You can click on the pixel buttons below to draw simple images or do the exercises on paper.

Rows: Columns:

Try drawing in the following RLE compression and see if you get something you recognize. Remember the first number in each row is the number of white pixels.

0, 6

4, 1, 1

3, 1, 2

2, 1, 3

1, 1, 4

0, 6

Continue with the rest of the exercises in the Image Representation Activity Worksheetarrow-up-right.

Run-Length Encoding

The following video presentation explores some of the details of RLE image compression (an example of lossless compression) and illustrates some of the ways that images and other data are represented with binary numbers.

Activity: 3.3.2.1 YouTube (xn3-BAiaJ1k)

  • Fewer bits does not necessarily mean less information.

  • The amount of size reduction from compression depends on both the amount of redundancy in the original data representation and the compression algorithm applied.

  • The amount of compression can vary depending on how many bits are used to represent each pixel in the image.

  • The amount of compression also depends on the number of different colors used in the actual image. For our black and white spaceship there were only 2 colors, so there were relatively few color changes and therefore lots of long runs. If it were a colored spaceship, there would be many color changes and therefore fewer long runs. So we would get much less compression.

  • A lossless compression algorithm is one in which no data are lost; the original data can be completely recovered. An example of lossless compression is RLE.

  • A lossy compression algorithm is one in which some data are lost; the original data cannot be completely restored. An example of lossy compression is JPEG.

  • Lossy data compression algorithms can usually reduce the number of bits stored or transmitted more than lossless compression algorithms.

Other Activities

Your teacher may ask you to do some of the following activities in POGIL teams or pairs.

  1. American Standard Code for Information Interchange (ASCII) is character code that includes 128 characters. Write your own message in binary that someone else could decode using an ASCII to Binary tablearrow-up-right. Trade messages in class and decode each others.

  2. In web pages and in Thunkable, colors are represented using hexcode for Red, Green, and Blue values. Here’s a color mixer apparrow-up-right that lets you explore the different colors that are used in Web pages. You can also try making a Custom Color in Thunkable by changing the Screen's BackgroundColor property to Custom. How many bits are used to represent the colors in Hex Code? Figure out the Hex code for pure red? pure green? pure blue?

  3. Research another image type (e.g. GIFarrow-up-right, PNGarrow-up-right, BMParrow-up-right, TIFFarrow-up-right, etc.) and compare and contrast the data needed to store information about the images. Include what type of compression is used.

  4. If you have a digital camera or a smartphone or tablet, find out what image representation scheme it uses? How come all images are not the same size?

  5. ASCII is one type of character code, but 128 characters is not enough for today’s computers, which can represent Chinese, Hindi, and scripts from many other languages. Today’s computers use a system called Unicode, which has more than 100,000 different characters and covers more than 100 different scripts (languages). Use this Unicode converterarrow-up-right to convert these Chinese characters to their hexadecimal Unicode values and to their corresponding decimal values: 国话. Convert these Greek letters: οι. Convert these Russian letters: Я ю.

3.3.3. Summary

In this lesson, you learned how to:

Learning Objective DAT-1.A: Explain how data can be represented using bits.

Learning Objective DAT-1.D: Compare data compression algorithms to determine which is best in a particular context.

3.3.4. Still Curious?

How do Snapchat filters work? If you or someone you know uses the social media app Snapchat, they have probably used one of those cool filters. But, how exactly do those filters work? Watch the video below to learn more about the algorithm and pixel data behind Snapchat filters.

Activity: 3.3.4.1 YouTube (Pc2aJxnmzh0)

How does JPEG encoding work? JPEG is an example of a lossy compression algorithm. JPEG, which uses the file extension .jpg or .jpeg, is the most common format used today to represent images.The JPEG algorithm was created by the Joint Photographic Experts Group (JPEG), hence its name. The fact that JPEG is a lossy technique means that some of the information present in the image is lost during compression and cannot be recovered. Here is a video lecture on the JPEG compression algorithmarrow-up-right (Teacher Tube versionarrow-up-right). The compression algorithm involves some math, but the video describes just enough of the math so that you can see how JPEG works. The video is a summary of an excellent, more detailed presentation by Randell Heymanarrow-up-right -- you should really check out the Heyman video if you are interested in more of the mathematical details.

How are audio files digitized? What about audio files? How are they digitized and converted to bits? Watch the following videoarrow-up-right for a summary of how audio files are converted from analog to digital format. Analog refers to data with values that change continuously, or smoothly, over time, like sound or music files. Analog data is converted to a digital forms, 0s and 1s in binary, using a sampling technique, which means measuring values of the analog signal at regular intervals (usually in time or space) called samples. The samples are measured to figure out the exact bits required to store each sample. The use of digital data to approximate real-world analog data is a great example of abstraction!

Activity: 3.3.4.2 YouTube (ALFXrlrnAcI)

Here's a fun activity if you have a computer or tablet with a microphone. Go to https://academo.org/demos/virtual-oscilloscope/arrow-up-right or a different audio recorder and see the sound waves that your voice can produce. Think about how they would be represented in 0s and 1s.

Different audio file extensions compress the audio data in different ways. WAV files are huge because they just store snapshots of digitized values at different points of time with no compression. MP3 formatting compresses audio files by removing parts of the audio signal which the human ear cannot easily hear. They save on space while preserving good audio quality.

3.3.5. Self-Check

Vocabulary

Here is a table of some of the technical terms we've introduced in this lesson. Hover over the terms to review the definitions.

ASCII

bit

bitmap

byte

pixel

lossless compression

lossy compression

run length encoding

analog

sampling

Check Your Understanding

Complete the following self-check exercises.

Q-4: In the video, you learned how black and white images can be represented using bits and numbers. What letter of the alphabet would be represented by the following set of numbers representing its RLE compression? You can use the interactive pixel grid above or in another tab to work this out.

1, 4, 2

1, 1, 3, 1, 1

1, 1, 3, 1, 1

1, 5, 1

1, 1, 4, 1

1, 1, 4, 1

1, 1, 4, 1

1, 5, 1

Activity: 3.3.5.1 Fill in the Blank (mcsp-3-3-1)

Q-5: Which set of numbers would encode the letter “c”? You can use the interactive pixel grid above or in another tab to work this out.

A.

1, 3

0, 1, 3

0, 2, 2

2, 2

3, 1

0, 3, 1

B.

1, 3, 1

0, 1, 3, 1

0, 1, 4

0, 1, 4

0, 1, 3, 1

1, 3, 1

C.

1, 1, 1

0, 3

0, 3

1, 1, 1

1, 1, 1

1, 1, 1

1, 1, 1

1, 1, 1

1, 1, 1

Choose one

Activity: 3.3.5.2 Multiple Choice (mcsp-3-3-2)

3.3.6. Sample AP CSP Exam Question

Q-6: Which of the following is a true statement about data compression?

A. There are trade-offs involved in choosing a compression technique for storing and transmitting data.

B. No matter what compression technique is used, once a data file is compressed, it cannot be restored to its original state.

C. Sending a compressed version of a file ensures that the contents of the file cannot be intercepted by an unauthorized user.

D. Data compression is only useful for files being transmitted over the Internet.

Choose one

Activity: 3.3.6.1 Multiple Choice (mcsp-3-3-3)

3.3.7. Reflection: For Your Portfolio

Answer the following portfolio reflection questions as directed by your instructor. Questions are also available in this Google Docarrow-up-right where you may use File/Make a Copy to make your own editable copy.

Last updated