Compression: DMET501 - Introduction To Media Engineering
Compression: DMET501 - Introduction To Media Engineering
Compression
Seif Eldawlatly
1
Compression
• Compression must often be applied to digital multimedia to save
storage space
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
0
1
2
3 RL code: (11144)(214)(426)
4
5
6
7
0 1 2 3 4 5 6 7
6
Huffman Coding
• Since the symbols ♣, ► and ☻ appear more than once. We can use
the following dictionary
• For images, colors appearing more frequent will have shorter codes in
the dictionary
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
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
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
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
14
JPEG Compression
• Such quantization process reduces the space needed to store the
image but results in loss of information
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
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
19
Spatial Compression
• The technique of compressing video sequences by applying JPEG
compression to each frame is called motion JPEG (MJPEG)
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
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
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
26