Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Image compression

1
3.4 Image compression
The graphic interchange format GIF
• Used in internet for the compression of images
• Color images – 24 bit pixels- 8 bit each R,G B
• Reduce the number of possible colors that are
present by choosing the 256 colors from the
original 224 colors that match most closely
The resulting table of colors therefore consists of
256 entries, each of which contains a 24-bit color
value

2
The graphic interchange format GIF
• Instead of storing each pixel as a 24 bit value, only the 8 bit
index to the table entry that contains the closest match color
is sent
• The table of colors can refer to the whole image
– global color table
• Portion of the image
• Local color table

• Contents of the table are sent along with the compressed


image data and other information –screen size, aspect ratio

3
• LZW coding can be used to obtain further levels
of compression
• Extending the basic color table dynamically as
the compressed image data is being encoded
and decoded
• Occurrence of common pixel values (long strings
of the same color) is detected and stored in the
table

4
5
3.4.1 Graphic interchange
format(GIF)
• GIF also allow an image to be stored and subsequently
transferred over the network in an interlaced mode
• Useful when transferring images over low bit rate
channels or Internet which provides a variable
transmission rate
• To achieve this compressed data is divided into 4 groups
• The first contains 1/8 of the total compressed image
data, the second a further 1/8, the third a further 1/4 ,
and the last the remaining 1/2

6
3.4.1 Graphic interchange format
• Figure 3.10

7
3.4.4 Digitized pictures
3.4.5 JPEG
• Defines a range of different compression
methods
• lossy sequential mode -known as the baseline
method
There are five main stages associated with this
mode:image/block preparation, forward DCT,
quantization, entropy encoding, and frame
building

8
3.4.5 JPEG
JPEG Encoder schematic

9
Image/block preparation
• In its pixel form, source image is made up of one or
more 2D matrices of values
• Monchrome- 1 matrix
• CLUT 1 matrix
• R,G,B – 3 matrices
• Y, Cr, Cb – 2 matrices smaller in size than Y for Cr and
Cb

10
3.4.5 JPEG
• Image/block preparation
-- Once the source image format has been
selected and prepared
-- Block preparation
-- It would be too time consuming to compute
the DCT of the total matrix in a single step so
each matrix is first divided into set of smaller
8× 8 submatrics as a block

11
3.4.5 JPEG
Image Preparation

12
3.4.5 JPEG
Block Preparation

13
3.4.5 JPEG
• Forward DCT
-- Each pixel value is quantized using 8 bits which
produces a value in the range 0 to 255 for the
intensity/luminance values-R,G,B or Y - and a
value in the range -128 to +127 for the two
chrominance values-Cb and Cr
-- All the values are first centered around zero by
subtracting 128
-- The input 2-D matrix is represented by :P[x,y]
and the transformed matrix by F[i, j]
14
15
• For i=j=0 the two cosine terms( and hence
horizontal and vertical frequency coefficients)
are both 0, since cos(0)=1 the value in F[0,0]
of the transformed matrix is simply a
summation of all the values in the input
matrix
• it is the mean of all 64 values in the matrix, it
is known as the DC coefficient

16
• Since the values in all the other locations of the
transformed matrix have a frequency coefficient
associated with them, either horizontal (x=1-7 for
y=0), vertical (x=0 for y=1-7) or both (x=1-7 for
y=1-7) they are known as AC coefficients
• For j=0 only horizontal frequency coefficients are
present which increase in frequency for i=1-7
• For i=0 only vertical frequency coefficients are
present which increase in frequency for j=1-7
• In all other locations both horizontal and vertical
frequency coefficients are present to varying
degrees.
17
3.4.5 JPEG
• DCT Computation features

18
3.4.5 JPEG
• Quantization
-- The human eye responds primarily to the DC
coefficient and the lower spatial frequency
coefficients
• If the magnitude of a higher frequency coefficient is
below a certain threshold the eye will not detect it
-- Quantization phase - dropping-in practice, setting to
zero-those spatial frequency coefficients in the
transformed matrix whose amplitudes are less than a
defined threshold value
Although eye is less sensitive to these frequency
coefficients, once dropped cannot be retrieved 19
3.4.5 JPEG
• The quantization process aims to reduce the size of
the DC and AC coefficients so that less bandwidth is
required
• Instead of simply comparing each coefficient with the
threshold value,a division operation is performed
using the defined threshold value as the divisor
• If the resulting (rounded) quotient is zero, coefficient
is less than the threshold value, if it is non zero , this
indicates the numer of times the coefficient is greater
than the threshold rather than its absolute value
• The quantization table with the threshold value to be
used with a particular DCT coefficient in the
corresponding position in the matrix
• If the divisor is 16, it saves 4 bits 20
• Sensitivity of the eye varies with spatial frequency
• Amplitude threshold below which eye will detect a
particular spatial frequency also varies
• The threshold values vary for each of the 64 DCT
coefficients
• Held is a 2D matrix- quantization table with a
threshold value to be used with a particular DCT
coefficient in the corresponding position in the
matrix
• The choice of threshold values a compromise
between the level of compression and the amount of
information loss that is acceptable

21
22
3.4.5 JPEG
Example computation of a set of quantized DCT coefficients

23
3.4.5 JPEG
• An example set of threshold values is given in the
quantization table , it can conclude a number of
points:
-- The computation of the quantized coefficients
involves rounding the quotients to the nearest
integer value
-- The threshold values used, increase in magnitude
with increasing spatial frequency
-- The DC coefficient in the transformed matrix is largest
-- Many of the higher-frequency coefficients are zero

24
Entropy encoding
• Comprises of 4 steps
– Vectoring, Differential encoding, run lengrth
encoding, Huffman encoding
• Vectoring: The various entropy encoding algorithms
operate on a 1D string of values - vector
• must represent the matrix as a vector
• If we simply scanned the matrix line by line approach
then the resulting vector contain a mix of non-zero and
zero values
• Does not lend itself to compression
• To exploit ong strings of zeros in the vector, zig-zag scan
is used
25
a.
3.4.5
Vectring using zig zag scan
JPEG
b. Principle c. vecor

26
3.4.5 JPEG
• -- the DC coefficient and lower-frequency AC
coefficients-both horizontal and vertical-are scanned
first
• All the higher frequency coefficients are in a
sequential order – more suitable for compression

27
3.4.5 JPEG
• Differential encoding
-- the first element in each transformed block is the DC
coefficient which is a measure of the average
color/luminance/chrominance associated with the
corresponding 8X8 block of pixels
-- the DC coefficient varies only slowly from one block
to the next because of the small area covered by
each block
--differential encoding since this encodes only the
difference between each pair of values
-- for example, if the sequence of DC coefficeints in
consecutive quantized blocks-one per block –was: 12,
28
13, 11, 11, 10, …
3.4.5 JPEG
-- the corresponding difference values would be : 12, 1,
-2, 0, -1, …
-- the difference values are then encoded in the form
(SSS,value)
-- the SSS field indicates the number of bits needed to
encode the value
-- the value field the actual bits that represent the value
-- Figure 3.19
-- Example 3.5
29
Variable length coding
a. coding categories . b. Default Huffman code words

30
Variable length coding
a. coding categories . b. Default Huffman code words

31
3.4.5 JPEG
• Run-length encoding
-- The remaining 63 values in the vector are the
AC coefficients
-- Each pair is made up of (skip, value) where
skip is the number of zeros in the run
Value- next non zero coefficient
-- Figure 3.18 would be encoded as:
(0,6) (0,7)(0,3)(0,3) (0,3) (0,2)(0,2)(0,2)(0,2)(0,0)
-- Final pair (0,0) indicates the end of the string
for this block and that all the remaining
coefficients in the block are zero 32
3.4.5 JPEG
• Huffman encoding
-- Significant levels of compression can be obtained by
replacing long string of binary digits by a string of
much shorter codewords
-- The length of each codeword being a function of its
relative frequency of occurrence
For each of the runlength encoded AC coeffcients, in the
block the bits that makeup the skip and SSS fields are
treated as a single symbol and this is encoded using
either the default table or a tale that is sent along with
the encoded bitstream
33
3.4.5 JPEG
• Frame building
-- The frame builder is to encapsulate all the
information relating to an encoded
image/picture in this format
-- Figure 3.20

34
3.4.5 JPEG
JPEG encoder output bitstream format

35
Headers
• Frame Header
– width, height
– No. and type of components
– Digitization format used 4:2:2, 4:2:0

• Scan header-
• R,G,B
• No. of bits used to digitize the image
• Quantization table
36
3.4.5 JPEG
• Jpeg decoding – JPEG Decoder Schematic

37
• Frame decoder- identifies the control
information and tables within the various
headers
• Loads the contents of the related table and
passes the control information to image
builder
• Pass the compressed bit stream to Huffman
decoder- decompression operation

38
Reference:
• Fred Halsall, Multimedia Communications-
Applications, Networks, Protocols and
Standards, (1e), Pearson Education India,2002

You might also like