In which type of data compression we can reconstruct only an approximation of the original data?

If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Summary

Materials

  • Day 15 PowerPoint deck
  • Extension - Reduce the file size of your Word documents

Instructional Activities and Classroom Assessments

  1. Data Compression Introduction (10 minutes)
  2. Lossless and Lossy in Images (20 minutes)
  3. Debrief (5 minutes)
  4. Text Compression (10 minutes)
  5. Extension Activity

Learning Objectives

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

Essential Knowledge

  • DAT-1.D.1 Data compression can reduce the size (number of bits) of transmitted or stored data.
  • DAT-1.D.2 Fewer bits does not necessarily mean less information.
  • DAT-1.D.3 The amount of size reduction from compression depends on both the amount of redundancy in the original data representation and the compression algorithm applied.
  • DAT-1.D.4 Lossless data compression algorithms can usually reduce the number of bits stored or transmitted while guaranteeing complete reconstruction of the original data.
  • DAT-1.D.5 Lossy data compression algorithms can significantly reduce the number of bits stored or transmitted but only allow reconstruction of an approximation of the original data.
  • DAT-1.D.6 Lossy data compression algorithms can usually reduce the number of bits stored or transmitted more than lossless compression algorithms.
  • DAT-1.D.7 In situations where quality or ability to reconstruct the original is maximally important, lossless compression algorithms are typically chosen.
  • DAT-1.D.8 In situations where minimizing data size or transmission time is maximally important, lossy compression algorithms are typically chosen.

Details

1. Data Compression introduction (10 minutes)

  • Explain what data compression is.
  • Explain why we need data compression.
  • Discuss the cost of data storage.
  • Discuss the two types of data compression.

2. Lossless and Lossy in Images (20 minutes)

  • Discuss lossy and lossless in images.
  • Create an image activity.

3. Debrief (5 minutes)

  • Discuss students observations regarding the different image files they created.

4. Text Compression (10 minutes)

  • Discuss how text compression programs work.
  • Discuss Run Length Encoding.

5. Extension activity

  • If you finish early, students can read Extension - Reduce the file size of your Word documents.

What are lossless and lossy compression?

Lossless and lossy file compression describe whether all original data can be recovered when the file is uncompressed.

With lossless compression, every bit of data originally in a file remains after it is uncompressed, and all the information is restored. Lossy compression reduces a file by permanently eliminating certain information, especially redundant information.

When the file is uncompressed, some of the original information is not there, although the user may not notice it.

What is file compression?

Digital files such as image files are often "compressed" to reduce their size and/or to change various attributes, such as:

  • file type
  • dimensions
  • resolution
  • bit depth

Compression reduces the size of a file, often without appreciable loss of information. It can be either lossless or lossy.

A smaller-sized compressed file can be restored to its larger form -- in its entirety or with some data loss, depending on the compression type -- by decompression.

Lossless compression vs. lossy compression

Lossless compression restores and rebuilds file data in its original form after the file is decompressed. For example, when a picture's file size is compressed, its quality remains the same.

The file can be decompressed to its original quality without any loss of data. This compression method is also known as reversible compression.

With this method, although file sizes are reduced, the reduction is less compared to reduction using lossy compression.

In lossy compression, the data in a file is removed and not restored to its original form after decompression. Specifically, data is permanently removed, which is why this method is also known as irreversible compression.

This data loss is not usually noticeable. However, the more a file is compressed, the more degradation occurs, and the loss eventually becomes visible.

Lossy compression reduces file size much more than the file size achieved after lossless compression.

In which type of data compression we can reconstruct only an approximation of the original data?
Lossless and lossy are data compression methods to reduce file sizes.

Applications of lossless and lossy compression

Lossless compression is mainly used to compress:

  • images
  • sound
  • text

It is generally the technique of choice for detailed product images, photography showcases, text files and spreadsheet files, where the loss of picture quality, words or data (e.g., financial data) could pose a problem.

The Graphics Interchange File (GIF), an image format used on the internet, is generally compressed using lossless compression. RAW, BMP and PNG are also lossless image formats.

Lossy compression is mainly used to compress:

  • images
  • audio
  • video

This technique is preferred for audio and video files where some amount of information loss is acceptable since it's unlikely to be detected by most users. The JPEG image file, commonly used for photographs and other complex still images on the web with no transparency, is generally compressed using lossy compression.

Using JPEG compression, the creator can decide how much loss to introduce, and how much of a trade-off is acceptable between file size and image quality.

Lossy compression is also suitable for websites featuring JPEG files and fast loading times since the compression ratio can be adjusted while maintaining the right balance.

Algorithms used in lossless and lossy compression

Different kinds of algorithms are used to reduce file sizes in lossless and lossy compression.

The algorithms used in lossless compression are:

  • Run Length Encoding
  • Lempel-Ziv-Welch (LZW)
  • Huffman Coding
  • Arithmetic Encoding

The algorithms used in lossy compression are:

  • Transform Coding
  • Discrete Cosine Transform
  • Discrete Wavelet Transform
  • Fractal Compression

Advantages and drawbacks of lossless compression

The key benefit of lossless compression is that the quality of the file (e.g., an image) can be retained while achieving a smaller file size.

In JPEG and PNG files, this is done by removing unnecessary metadata. For applications where it's important to retain the quality of the file, lossless compression is the better choice.

The drawback of this compression technique is that larger file sizes are required to maintain post-compression quality.

Advantages and drawbacks of lossy compression

Lossy compression results in a significantly reduced file size (smaller than lossless compression), which is its most noteworthy benefit. It is supported by many tools, plugins and software products that let the user choose their preferred degree of compression.

The disadvantage is that it also results in quality loss, which may not be acceptable for some applications or users. The higher the compression ratio, the more quality degradation. Additionally, the original file -- with original quality -- cannot be recovered after compressing.

In which type of data compression we can reconstruct only an approximation of the original data?
Choosing lossless or lossy data compression comes down to three things: the application it is being used for, the acceptable level of quality loss and the desired file size.

What is the best choice for compression: Lossless or lossy?

There is no "right" or "best" answer when it comes to choosing between lossless vs. lossy compression. The choice depends on:

  • the application
  • acceptable level of quality loss
  • desired file size

So, for example, a blog or portfolio website could benefit from lossy compression since it offers significant file size reduction, saves storage space and improves site performance and user experience. On the other hand, a website that requires high-quality photos would be better off with lossless compression.

It is also possible to use both types of compression for the same application.