Chapter 5 Data Compression
Chapter 5 Data Compression
Vector images: A typical 640x480 image has 500 lines approximately. Each line
has 2 coordinates (x,y) each and an 8-bit attribute field. x requires 10 bits
(log2(640)) and y requires 9 bits (log2(480)).We need 46 bits per line ( ). The
storage required is 500x46/8=2875 or 2.8KByte per image.
Coding Requirements
• Bitmap images: Individual pixels of a bitmap can be coded using 256
different colours, requiring 1 Byte per pixel.640x480x1Byte= or
300KBytes per image.
• Sound: Uncompressed speech of telephone quality is sampled at
8kHz and quantized using 8 bits per sample, yielding a data stream of
64 Kbits/sec. Storage required will be (64Kbps/8)x(1sec/1024) =
8KByte for a 1 second sound.
• Sound: Uncompressed stereo audio signal of CD quality is sampled at
44.1kHz and quantized using 16 bits per sample, yielding a data
stream of 176,400 bytes/sec. Storage required will be 172KByte for a
1 second sound.
Coding Requirements
• Video: 25 full frames per second. Luminance(brightness) and
chrominance(signal used to convey color information) of each pixel
are coded using a total of 3 bytes. Data rate is
640x480x25x3bytes=23,040,000 bytes/sec. Storage required will be
21.98MByte for 1 second of video. (Multiply by 5 for HDTV!)
Data Compression
• Data compression is the process of modifying, encoding or converting
the bits structure of data in such a way that it consumes less space on
disk.
• It enables reducing the storage size of one or more data instances or
elements. Data compression is also known as source coding or bit-
rate reduction
Why Compression?
• To reduce the volume of data to be transmitted (text, fax, images)
• To reduce the bandwidth required for transmission and to reduce
storage requirements (speech, audio, video)
Importance of Data Compression
• Reduced Storage Costs: Compressed data requires less storage space, which can
significantly reduce storage costs for businesses dealing with large volumes of
data.
• Increased Data Transfer Speed: Smaller file sizes allow for faster data transfer
across networks and systems, improving overall data processing and
communication efficiency.
• Improved Data Processing and Analysis: Compressed data can be processed and
analyzed more quickly, enabling faster insights, decision-making, and advanced
analytics.
• Optimized Resource Utilization: By reducing the size of data files, compression
enables efficient utilization of computing resources, such as CPU cycles and
memory.
• Enhanced Data Security: Compression techniques can also be applied to encrypt
and secure data, protecting sensitive information from unauthorized access.
Data Compression Methods
Data Compression Methods
• Lossless Methods:
▪ the compression process does not reduce the amount of if information.
▪ Original can be reconstructed exactly.
• Lossy Methods:
▪ the compression process reduces the amount of information.
▪ Only an approximation of the original can be reconstructed.
Categories of Compression Techniques
• Entropy coding is lossless
• Source coding and hybrid coding are lossy.
Source, Entropy and Hybrid Coding
• Frequencies of characters:
• Sorted order:
• Without using the Huffman coding algorithm, the size of the text was 88 bits.
Whereas after encoding the text, the size is reduced to 24 + 11 + 16 = 51 bits.
Huffman Coding – Example 2
Huffman Coding – Example 2
Huffman Coding – Example 2
Huffman Coding – Example 2
• We assign a weight to each edge. Note that each left edge-weighted is
0 and the right edge-weighted is 1.
Huffman Coding – Example 2
• Here, no of character = 6
• No of bits required to represent character = 2^3 i.e. code length will
be 3.
• Bits used before coding: 5*3 +9*3 + 12*3 + 13*3 +16*3 + 45*3 = 300
• Bits used after coding: 5*4 + 9*4 + 12*3 + 13*3 + 16*3 + 45*0 = 179
• Therefore, (300-179)/300 = 40.3% of space is saved after Huffman
coding
Assignment
1. Find the Average Code Length for the String and Length of the
Encoded String of the given string “abcdrcbd”. Use the Huffman
coding technique to find the representation bits of the character.
Hints:
• Average Code Length = ∑ ( frequency × code length ) / ∑ ( frequency )
• Length= Total number of characters in the text x Average code length per character
• Using DCT, for each channel, each block of 64 pixels can be reconstructed
by multiplying a constant set of base images by their corresponding weight
values and then summing them up together. Here is what the base images
look like:
Steps of JPEG Compression process
• For every block of 64 pixels, we’ll have three weight matrices, one for
luminance and two for chrominance. In addition, no information is
lost in this phase.
Steps of JPEG Compression process
• Step 4: Human eyes can't see some image details with high
frequencies.
• DCT matrix keeps only low-frequency information.
• To use fewer bits, we do quantization.
• We divide by a preset table and round to nearest whole number
Steps of JPEG Compression process
• Here is what a quantization table for chrominance channels looks like:
for the luminance channel:
Steps of JPEG Compression process
• We can see that the quantization tables have higher numbers at the
bottom right, where high-frequency data is located, and have lower
numbers at the top left, where low-frequency data is located. As a result,
after dividing each weight value, high-frequency data is rounded to 0:
• Now we have three matrices containing integer values for every block of 64
pixels, one for luminance and two for chrominance.
Steps of JPEG Compression process
• Now all that’s left to do is to list the values that are inside each
matrix, run RLE (Run Length Encoding) since we have a lot of zeroes,
and then run the Huffman Coding algorithm before storing the data.
• RLE and Huffman Coding are lossless compression algorithms that
reduce the space needed to store information without removing any
data.
• As we can see, the result of quantization has many 0s toward the
bottom left corner. To keep the 0 redundancy, the JPEG algorithm
does a zig-zag scanning pattern that keeps all zeroes together:
Steps of JPEG Compression process
• After zig-zag scanning, we get a list of integer values, and after
running RLE on the list, we get each number and how many times
they’re repeated.
• Finally, JPEG runs Huffman coding on the result, and the values that
have more frequency (like the zeroes) are represented with fewer bits
than less frequent values.
• No data is lost during this phase.
MPEG compression process
• MPEG stands for Moving Picture Coding Exports Group.
• MPEG algorithms compress data to form small bits that can be easily
transmitted and then decompressed.
• MPEG achieves its high compression rate by storing only the changes
from one frame to another, instead of each entire frame.
• The information is then encoded using a technique called Discrete
Cosine Transform (DCT).
• MPEG uses a type of lossy compression, since some data is removed.
But the diminishment of data is generally imperceptible to the human
eye
MPEG compression process
• MPEG compression removes two types of redundancies:
• Spatial redundancy:
▪ Pixel values are not independent, but are correlated with their neighbour
both within the same frame and across frames. So, to some extent, the value
of a pixel is predictable given the values of neighbouring pixels.
▪ It is removed with the help of DCT compression
MPEG compression process
• Temporal redundancy:
▪ Pixels in two video frames that have the same values in the same location
(some objects repeated again and again in every frame).
▪ It is removed with the help of Motion compensation technique Macroblock
▪ It is the basic hierarchical component used achieving high level of
compression.
▪ The key to achieving a high rate of compression is to remove much redundant
information as possible.
▪ Entropy encoding and Huffman coding are two schemes used for encoding
video information.
▪ MPEG takes the advantage of the fact that there exists a correlation between
successive frames of moving pictures.
MPEG compression process
MPEG compression process
• The MPEG compression algorithm encodes the data in 5 steps.
• First a reduction of the resolution is done, which is followed by a
motion compensation in order to reduce temporal redundancy.
• The next steps are the Discrete Cosine Transformation (DCT) and a
quantization as it is used for the JPEG compression; this reduces the
spatial redundancy (referring to human visual perception).
• The final step is an entropy coding using the Run Length Encoding and
the Huffman coding algorithm
MPEG compression process
Step 1: Reduction of the Resolution
• The human eye has a lower sensibility to colour information than to
dark-bright contrasts.
• A conversion from RGB-colour-space into YUV colour components
help to use this effect for compression.
• The chrominance components U and V can be reduced (subsampling)
to half of the pixels in horizontal direction (4:2:2), or a half of the
pixels in both the horizontal and vertical (4:2:0).
MPEG compression process
Step 2: Motion Estimation
• An MPEG video can be understood as a sequence of frames. Because
two successive frames of a video sequence often have small
differences (except in scene changes), the MPEG-standard offers a
way of reducing this temporal redundancy.
• It uses three types of frames: I-frames (intra), P-frames (predicted)
and B-frames (bidirectional).
MPEG compression process
• The I-frames are “key-frames”, which have no reference to other frames
and their compression is not that high.
• The P-frames can be predicted from an earlier I-frame or P-frame.
• P-frames cannot be reconstructed without their referencing frame, but
they need less space than the I-frames, because only the differences are
stored.
• The B-frames are a two directional version of the P-frame, referring to both
directions (one forward frame and one backward frame).
• B-frames cannot be referenced by other P- or B-frames, because they are
interpolated from forward and backward frames.
• P-frames and B-frames are called inter coded frames, whereas I-frames are
known as intra coded frames.
MPEG compression process
• The references between the different types of frames are realized by
a process called motion estimation or motion compensation.
• The correlation between two frames in terms of motion is
represented by a motion vector.
• The resulting frame correlation, and therefore the pixel arithmetic
difference, strongly depends on how good the motion estimation
algorithm is implemented.
MPEG compression process
The steps involved in motion estimation:
• Frame Segmentation - The Actual frame is divided into non
overlapping blocks (macro blocks) usually 8x8 or 16x16 pixels. The
smaller the block sizes are chosen, the more vectors need to be
calculated.
• Search Threshold - In order to minimize the number of expensive
motion estimation calculations, they are only calculated if the
difference between two blocks at the same position is higher than a
threshold, otherwise the whole block is transmitted.
MPEG compression process
• Block Matching - In general block matching tries to “stitch together”
an actual predicted frame by using snippets (blocks) from previous
frames.
• Prediction Error Coding - Video motions are often more complex, and
a simple “shifting in 2D” is not a perfectly suitable description of the
motion in the actual scene, causing so called prediction errors.
• Vector Coding - After determining the motion vectors and evaluating
the correction, these can be compressed. Large parts of MPEG videos
consist of B- and P-frames as seen before, and most of them have
mainly stored motion vectors.
MPEG compression process
Step 3: Discrete Cosine Transform (DCT)
• DCT allows, similar to the Fast Fourier Transform (FFT), a
representation of image data in terms of frequency components.
• So the frame-blocks (8x8 or 16x16 pixels) can be represented as
frequency components. The transformation into the frequency
domain is described by the following formula:
MPEG compression process
Step 4: Quantization:
• During quantization, which is the primary source of data loss, the DCT
terms are divided by a quantization matrix, which takes into account
human visual perception.
• The human eyes are more reactive to low frequencies than to high
ones. Higher frequencies end up with a zero entry after quantization
and the domain was reduced significantly.
MPEG compression process
Step 5: Entropy Coding
• The entropy coding takes two steps: Run Length Encoding (RLE ) [2]
and Huffman coding [1]. These are well known lossless compression
methods, which can compress data, depending on its redundancy, by
an additional factor of 3 to 4.
Assignment
• Lossy Sequential DCT-based Mode
• Expanded Lossy DCT-based Mode