0% found this document useful (0 votes)
54 views26 pages

Compression: DMET501 - Introduction To Media Engineering

Compression techniques can be either lossless or lossy. Lossless compression techniques like run-length encoding and Huffman coding compress data without losing any information, while lossy techniques like JPEG discard unnecessary data in a way that is typically imperceptible to humans. Video compression standards like MPEG use both spatial compression on individual frames and temporal compression by encoding differences between frames.

Uploaded by

Mohamed Zakaria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views26 pages

Compression: DMET501 - Introduction To Media Engineering

Compression techniques can be either lossless or lossy. Lossless compression techniques like run-length encoding and Huffman coding compress data without losing any information, while lossy techniques like JPEG discard unnecessary data in a way that is typically imperceptible to humans. Video compression standards like MPEG use both spatial compression on individual frames and temporal compression by encoding differences between frames.

Uploaded by

Mohamed Zakaria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Winter 2020

DMET501 – Introduction to Media Engineering

Compression

Seif Eldawlatly

1
Compression
• Compression must often be applied to digital multimedia to save
storage space

• Compression can be lossless or lossy

Lossless Compression (ZIP)

2
Lossy Compression (JPEG, MP3)
Compression
• Data Compression Process:

3
Lossless Image Compression
• Consider the image given below. Using bitmap with no compression, if
the image is of a square of width 45mm and we use 24-bit for each
color at a resolution of 72 pixels/inch, we need a total of 48 kilobytes

• Such image can be stored in less space. For example, if the first row
consists of 128 pixels all with blue color, we can store such information
in 4 bytes only:
3 bytes to store the color and 1 byte to store the number of pixels
having such color (128)
4
Run-length Encoding (RLE)
• The technique of replacing a run of consecutive pixels of the same color
by a single color value and a count of the number of pixels in the run is
called Run-length Encoding

• Example: One simple RL code for binary images


(row, {first element in run, last element in run}*)*

0
1
2
3 RL code: (11144)(214)(426)
4
5
6
7
0 1 2 3 4 5 6 7

• The effectiveness of such method depends on the image that is being


compressed
5
Huffman Coding
• In bitmapped images, if we have 256 colors, each pixel is normally
represented by 8 bits

• Compression could be achieved if colors that appear more frequently


are assigned fewer bits (variable-length codes). This is the basic idea of
Huffman Coding
• Example on text representation (not images):
Suppose we have a message consisting of 5
symbols, e.g. [►♣♣♠☻►♣☼►☻]

Since we have 5 symbols, then we need 3 bits


to represent each. The total size of the
message is then 3 x 10 = 30 bits

6
Huffman Coding
• Since the symbols ♣, ► and ☻ appear more than once. We can use
the following dictionary

• Using this dictionary, the message ►♣♣♠☻►♣☼►☻ will be


represented by (3 x 2) + (3 x 2) + (2 x 2) + 3 + 3 = 22bits

• For images, colors appearing more frequent will have shorter codes in
the dictionary

• LZW (Lempe, Ziv and Welch) is a variant of Huffman coding that


constructs the dictionary optimally
7
Huffman Coding
• Example: Consider a dataset with 6 symbols and their corresponding
probabilities

1- To find the Huffman code, sort the symbols


in descending order according to their
probabilities as shown

2- Combine the bottom two symbols (least probabilities). Repeat this


process until you have two remaining symbols only

8
Huffman Coding
3- Code each reduced source starting with the last level and going
backwards

• From the obtained code, the average number of bits Lavg needed to
represent each symbol is
Lavg = 0.4x1 + 0.3x2 + 0.1x3 + 0.1x4 + 0.06x5 + 0.04x5 = 2.2

9
Huffman Coding
• The resulting code is uniquely decodable
Example: The code 010100111100 corresponds to one message only
which is a3 a1 a2 a2 a6

• When the number of symbols to be coded is large, constructing


Huffman code is not efficient

• Near-optimal variants of Huffman code have been proposed that are


more efficient

10
Lossy Image Compression
• Lossless compression can be applied to data types such as text and
executable programs where the corruption of one bit invalidates the
whole data

• Images, however, can tolerate some data loss that would be invisible to
the human eye

• JPEG (Joint Photographic Experts Group) is the most commonly used


lossy compression method for still images

• JPEG is best suited for photographs

11
JPEG Compression
• Any image can be considered as 3-dimensional function with x and y
coordinates define the pixel position and the z coordinate represents a
height that corresponds to the color

Original Image

Pixel Values Interpreted as Height


• As can be seen, edges are represented as steep slopes in the height
figure
12
JPEG Compression
• Such steep slopes represent high-frequencies in the frequency-domain
representation of the image

• High-frequency information can be discarded from an image without


perceptible loss of quality, because people do not perceive the effects
of high frequencies in images very accurately

• JPEG first uses Discrete Cosine Transform (DCT) to find the


frequency representation of the image
Example:

13
Original Image DCT Representation
JPEG Compression
• In JPEG, images are divided into 8 x 8 pixel squares, each of which is
transformed separately using DCT to reduce computational complexity

• Applying the DCT does not reduce the size of the data, since the array
of frequency coefficients is the same size as the original pixel array

• However, since high frequencies are explicitly separated, they can be


easily discarded or given fewer levels in quantization
Example:
If the value produced by the DCT for each frequency ranges from 0 to
255:
- Lowest-frequency coefficients can have any value from 0 to 255
- Slightly higher frequencies might only have values divisible by 4
- Highest frequencies might only have the value 0 or 128

14
JPEG Compression
• Such quantization process reduces the space needed to store the
image but results in loss of information

• After quantization there will usually be many zero coefficients. These


are RLE-encoded, using a zigzag sequence to maximize the length of
the runs

• The non-zero coefficients are compressed using Huffman encoding


15
JPEG Compression
• Decompression is performed by reversing the process, using the
Inverse DCT to recover the image from its frequency domain
representation

• The decompressed image may exhibit compression artifacts, including


blurring and visible edges at the boundaries between the 8×8 pixel
blocks, especially at low quality settings

16
JPEG2000 Compression
• JPEG2000 improves on JPEG in many areas, including image quality at
high compression ratios. It can be used losslessly as well as lossily

• For JPEG2000 compression the image is divided into tiles, but these
can be any size, up to the entire image

• Discrete Wavelet Transform (DWT) is applied to the tiles, generating a


wavelet decomposition, comprising a coarse (low resolution) version of
the image and a set of detail coefficients that can be used to add
progressively more detail to the image

17
JPEG2000 Compression
• The detail coefficients in the wavelet decomposition may be quantized
and are then losslessly compressed using arithmetic encoding

18
Video Compression
• The input to any video compression algorithm consists of a sequence of
bitmapped images

• There are two ways in which this sequence can be compressed:


- Spatial Compression: Compressing each individual image in
isolation using image compression techniques

- Temporal Compression: Compressing frames by only storing


differences among successive frames

• Spatial and temporal compressions are used together in most


contemporary video codecs

19
Spatial Compression
• The technique of compressing video sequences by applying JPEG
compression to each frame is called motion JPEG (MJPEG)

• Chrominance sub-sampling is nearly always applied before any


compression

• DV compression is purely spatial. It extends the JPEG technique to


compress video files
20
Temporal Compression
• All modern video codecs use temporal compression to achieve higher
compression ratio or better quality relative to MJPEG

• Temporal compression works by computing the difference between


frames instead of storing every one in full

21
Temporal Compression
• The MPEG-1 (Moving Picture Experts Group) standard represents the
first systematic temporal compression standard

• In MPEG terminology
- I-pictures (Intra) represent reference frames and are only spatially
compressed
- P-pictures (Predictive) are computed from a preceding I- or P-picture

22
Temporal Compression
• Motion compensation is the technique of incorporating a record of the
relative displacement of objects in the difference frames, as a motion
vector
Frame 1 Frame 2

Without motion With motion


compensation, compensation,
pixels shown in black we only need to
is what needs to be store the
stored in the displacement vector
difference frame of the fish and the
pixels shown in
black from the
second frame

23
Temporal Compression
• B-pictures (Bi-directional) use following pictures as well as preceding
ones as the basis of frame differences and motion compensation

With motion Frame 1 Diff 1 Frame 2


compensation, Frame
2 can be obtained
from Frame 1 using
Diff 1. It can also be
obtained from Frame 3
using Diff 2 which
gives smaller
representation

With motion
compensation, Frame
2 can also be obtained Diff 2 Frame 3 Diff 3
from Frame 1 and
Frame 3 using Diff 3
which gives much 24
smaller representation
Temporal Compression
• A video sequence is encoded as a Group of Pictures (GOP). If B-
pictures are used, a GOP may have to be reordered into display order
for decoding

25
Temporal Compression
• MPEG-4 Part 2 uses global motion compensation and sub-pixel motion
compensation to improve on the quality of MPEG-1 and MPEG-2

• H.264/AVC adds several extra techniques, including variable-sized


transform blocks and macroblocks, and a de-blocking filter, to make
further improvements

• Windows Media 9 (standardized as VC-1) incorporates similar


improvements

• All modern codecs produce excellent quality at 2 Mbps and higher

26

You might also like