ho multimedia13

Upload: ananda-krishna

Post on 03-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Ho Multimedia13

    1/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 1

    JPEGJPEGz Joint Photographic Experts Group

    z ISO/ITU/IEC and it is defined as standard IS 10918

    z Focus attention on lossy sequential mode

    (the Baseline Mode)

    z Five main stages

    1. Image/Block Preparation

    . orwar3. Quantization

    4. Entropy Encoding

    5. Frame Building

    JPEG Encoder SchematicJPEG Encoder Schematic

    21

    3

    54

  • 7/28/2019 Ho Multimedia13

    2/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 2

    Frame builder

    Frame decoder

    11. Image/block preparation: block preparation. Image/block preparation: block preparation

    z continuous- tone monochrome image, single 2-Dmatrix is to store the set of 8-bit gray-level values

    z color image: if a CLUT is used just a single matrix

    z Color image: is represented in an R, G, B format threematrices are required, one each for the R, G, B.

    z color images: alternative form of representation, ,

    matrices for Cb and Cr) 3 are required,

    z The 4 alternative forms of representation are shown inFigure 3.15(a).

  • 7/28/2019 Ho Multimedia13

    3/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 3

    11. Image/block preparation: image preparation. Image/block preparation: image preparation

    z Once the source image format has been selected andprepared, the set of values in each matrix arecompressed separately using the DCT.

    z it would be too time consuming to compute theDCT of the total matrix in a single step.

    z so each matrix is first divided into a set of smaller 8 x8 submatrices. Each is known as a block and as we

    ,

    z these are then fed sequentially to the DCT whichtransforms each block separately.(left to right andtop to bottom)

    11. Image/block preparation: image preparation. Image/block preparation: image preparation

    planes into 8x8

    Blocks

    Can use either:R,G,B or

    Y,Cb,Cr

    z 640 x 480 pixels. Assuming a block size of 8 x 8 pixels, the image will be80 x 60 or 4800 blocks each of which, for a screen width of, say, 16 inches(400 mm), will occupy a square of only 0.2x0.2 inches (5x 5mm).

  • 7/28/2019 Ho Multimedia13

    4/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 4

    11. Image/block preparation: block preparation. Image/block preparation: block preparation

    Discrete Cosine Transform (DCT).Discrete Cosine Transform (DCT).

    z DCT: The transformation of a two-dimensional matrix ofpixel values into an equivalent matrix of spatial frequencycomponents.

    z The transformation operation itself is lossless (apart from somesmall rounding errors in the mathematics)

    z but, once the equivalent matrix of spatial frequency components(known as coefficients ) has been derived, then any frequencycomponents in the matrix whose amplitude is less than a definedthreshold can be dropped.

    z It is only at this point that the operation becomes lossy.

    z The basic principle behind the DCT is as shown in next figure

    (we shall describe it in more detail with image compression.

  • 7/28/2019 Ho Multimedia13

    5/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 5

    Transform Coding: (b) DCT Transform PrinciplesTransform Coding: (b) DCT Transform Principles

    Forward DCTForward DCT

    z each pixel value is quantized using 8 bits

    z 0 to 255 for intensity/luminance values R, G, B, or Y

    z -128 to +127 for the chrominance values Cb and Cr.

    z Before DCT, all the values are centered around zero by

    subtracting 128 from each intensity/luminance value.

    P[x,y] : the input 2-D matrix

    F[ i, j] transformed matrix by the DCT

    each 8 x 8 block of values is computed using the expression:

  • 7/28/2019 Ho Multimedia13

    6/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 6

    22. Forward DCT Equation. Forward DCT Equation

    ( ) ( ) ( ) ( )( ) ( )

    ( ) ( )

    7 7

    0 0

    2 1 2 11, , cos cos

    4 16 16

    1 2 , 0

    1,

    x y

    x i y jF i j C i C j P x y

    i jC i C j

    otherwise

    = =

    + +=

    ==

    Notes on DCTNotes on DCT

    z All 64 values in the input matrix, P[x, y] contribute to each entry inthe transformed matrix, F[ i, j].

    z For i= j = 0, since cos(0 )=1. the value in location

    F[0,0] it is the mean of all 64 values in the matrix and is known as.

    z all the other locations of the transformed matrix have a frequency

    coefficient associated with them either horizontal (x= 17 fory=0), vertical (x= 0 for y=17) or both (x= 17 for y = l 7)They are known as AC coefficients.

    .which increase in frequency for i = 17.

    z For i= 0, only vertical frequency coefficients are present whichincrease in frequency for j = 17.

    z In all other locations in the transformed matrix, both horizontaland vertical frequency coefficients are present to varyingdegrees.

  • 7/28/2019 Ho Multimedia13

    7/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 7

    DCT and color transitionsDCT and color transitions

    Hence those regions of a picture that contain a singlecolor will generate a set of transformed blocks all ofwhich will have

    z firstly, the same (or very similar) DC coefficient

    z secondly, only a few AC coefficients within them.

    Thus it is only those areas of a picture which containcolor transitions that will generate a set of transformed

    blocks with

    z erent DC coe c entsz A larger number of AC coefficients within them.

    these features that are exploited in the quantization andentropy encoding phases of the compression algorithm

    DCT Computation FeaturesDCT Computation Features

  • 7/28/2019 Ho Multimedia13

    8/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 8

    33. Quantization. Quantization

    z Eye responds primarily to the DC and lower frequencycomponents and varies with spatial frequency. therefore, thethreshold values used vary for each of the 64 DCT coefficients.

    z These are held in a two dimensional matrix known as thequantization table

    z Within the quantization process frequencies below athreshold are zeroed

    and the AC coefficients so that less bandwidth isrequired for transmission

    z This is achieved by dividing the coefficients by anormalization matrix which will zero the smallercoefficients

    ObservationsObservationsz The computation of the quantized coefficients involves dividing the

    coefficients by a normalization factor androunding thecoefficients to the nearest integer value

    z s an ar nc u es wo e au quan za on a es orcustomized one.

    z The normalization values used, in general, increase in magnitudewith increasing spatial frequency

    z The DC coefficient in the matrix is the largest

    z Many of the higher frequency coefficients are zero

    (exploited during the following entropy encoding stage.)

  • 7/28/2019 Ho Multimedia13

    9/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 9

    ExampleExample computationcomputation of a set of quantized DCT coefficientsof a set of quantized DCT coefficients

    ExampleExample 33..44

  • 7/28/2019 Ho Multimedia13

    10/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 10

    44. Entropy Coding. Entropy Coding

    the entropy encoding stage comprises four steps:

    1. Vectoring

    2. Differential encoding

    3. Run-length encoding

    4. Huffman encoding.

    VectoringVectoring

    entropy encoding algorithms operate on a one-

    dimensional strin of values that is a vector

    However, the output of the quantization is a 2-D.

    Thus, values are represented in the form of a single-

    dimension vector.

  • 7/28/2019 Ho Multimedia13

    11/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 11

    VectoringVectoringz In order to exploit the presence of the large number of zeros

    in the quantized matrix, a zig-zag scan of the matrix is used.

    z with this type of scan, the DC coefficient and lower-frequency AC coefficients both horizontal andvertical are scanned first.

    z Also, all the higher-frequency coefficients are in asequential order so making this form of representation moresuitable for compression.

    z The first is differential encoding, which is applied to the DCcoefficient only.

    z The second is run-length encoding, which is applied to theremaining values in the vector containing the ACcoefficients.

    Vectoring Using a Zigzag Scan: (a) Principle; (b)Vectoring Using a Zigzag Scan: (a) Principle; (b)

    for previous examplefor previous example

    AC ={(0,6) (0,7) (0,3) (0,3) (0,3) (0,2) (0,2) (0,2) (0,2) (0,0)}

  • 7/28/2019 Ho Multimedia13

    12/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 12

    DC CoefficientsDC Coefficients

    z DC coefficients are differentially encoded across theblocks

    Takes advantage of the local correlation in the average

    value among local blocks

    {12,13,11,11,10} -> {12,1,-2,0,-1}

    Differential encodingDifferential encoding

    z the first difference value always being encoded relativeto zero. The difference values are then encoded in theform (SSS, value) where the

    z SSS field indicates the number of bits needed to encodethe value

    z the value field the actual bits that represent the value.

    The rules used to encode each value are summarized

  • 7/28/2019 Ho Multimedia13

    13/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 13

    Default Huffman Code Words for SSSDefault Huffman Code Words for SSS

    (DC Coefficients)(DC Coefficients)

    z the number of bits required to encode each value isdetermined by its magnitude.

    As we can see:

    z A positive value is then encoded using the unsigned

    binary form

    z a negative value by the complement of this.

    z Note also that a value of zero is encoded using asingle 0 bit in the SSS field.

  • 7/28/2019 Ho Multimedia13

    14/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 14

    SSS vs. ValueSSS vs. Value

    Encoded ValueSSSDifference Value

    Null

    0,1

    00,01,10,11

    000,001,010,011,100,101,110,111.

    .

    .

    .

    .

    0

    1

    2

    34

    5

    6

    7

    8

    0

    -1,1

    -3,2,2,3

    -7..-4,4..7-15-8,815

    -31,-16,16.31

    -63..-32,32..63

    -127-64,64127

    -255....-128 128.255

    .

    .

    .

    9

    10

    11

    -511...-256,256511

    -1023...-512,5121023

    -2047......,-1023,1023....2047

  • 7/28/2019 Ho Multimedia13

    15/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 15

    (Value) Delta (SSS) Huffman Value Codeword

    12 12 4 101 1100 101||1100

    13 1 1 011 1 011||1

    11 -2 2 100 01 100||01

    11 0 0 010 Null 010||

    10 -1 1 011 0 011||0

    AC Coefficient EncodingAC Coefficient Encoding

    z AC coefficients are encoded within a block using run-length coding

    z Most coefficients are zeros due to normalization

    z Codes indicate the length of the zero run-length and thecoefficient value terminating it. i.e.

    (Skip, Value)

    z (Skip, Value) are mapped to (Skip, SSS, Value)

    SSS is Huffman Encoded,

    Value is encoded in 1s complement binary code words oflength specified by SSS

  • 7/28/2019 Ho Multimedia13

    16/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 16

    z Hence the 63 values in the vectorshown earlier inFigure 3.18 would be encoded as:

    , , , , , , , , , ,

    z Note that the final pair (0,0) indicates the end ofthe string for this block (EOB)

    zero. Also, that the value fieldis encoded in theform SSS/ value.

    Example 3.6

  • 7/28/2019 Ho Multimedia13

    17/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 17

    Huffman encodingHuffman encoding

    z Compression can be obtained by replacing long strings ofbinary digits by a string of much shorter codewords, (relativefrequency of occurrence).

    z Huffman coding algorithm. The same approach is used toencode the output of both the differential and run- lengthencoders.

    z For the differential-encoded DC coefficients in the block, the

    as shown in Example 3.5 but in a Huffman-encoded form.(correct your lecture notes)

    z This is done so that the bits in the SSS field have the prefixproperty.

  • 7/28/2019 Ho Multimedia13

    18/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 18

    Example 3.8

    As we can deduce from Example 3.8, to decode the receivedbit stream the receiver first searches the bit stream startingat the left most bit for a valid codeword and, on finding this(100), determines the corresponding skip (0) and SSS (3) fieldsfrom the Huffman table.

    The SSS field is then used to determine the number of bits in

    the run-length value field and, after reading and decodingthese, the process repeats until the EOB codeword isreceived indicating that the remaining coefficients are all zero.

    Because of the use of variable-length codewords in the variousparts of the entropy encoding stage, this is also known as thevariable-length coding (VLC) stage.

  • 7/28/2019 Ho Multimedia13

    19/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 19

    ProcessProcess

    (Skip,Value) (Skip,SSS) Codeword

    (0,6) (0,3) 100||110

    (0,7) (0,3) 100||111

    (0,3) (0,2) 01||11

    (0,3) (0,2) 01||11

    (0,3) (0,2) 01||11

    (0,2) (0,2) 01||10(0,2) (0,2) 01||10

    (0,2) (0,2) 01||10

    (0,2) (0,2) 01||10

    (0,0) (0,0) 1010 (EOB)

  • 7/28/2019 Ho Multimedia13

    20/21

    GMU - IT 481, Spring 2006 1/23/2006

    (C) Hung Nguyen, 2006 20

    55. Frame Building. Frame Building

    z Frame Header

    Overall width and height of the image in pixels

    The number and type of components that are used to

    represent the image (CLUT, RGB, YCbCr)

    Digitization format used: (4:2:2,4;2;0, etc)

    z Scan Header

    Identity of the components (RGB etc)

    The quantization table of values used to encode each

    component

    5. JPEG Encoder Output Bit Stream Format

  • 7/28/2019 Ho Multimedia13

    21/21

    GMU - IT 481, Spring 2006 1/23/2006

    JPEG decoder schematic