The task of compression consists of two components, an encoding algorithm that takes a file and...

18

Transcript of The task of compression consists of two components, an encoding algorithm that takes a file and...

Page 1: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.
Page 2: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.
Page 3: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

The task of compression consists of two components, an encoding The task of compression consists of two components, an encoding

algorithm that takes a file and generates a “compressed” representation algorithm that takes a file and generates a “compressed” representation

(hopefully with fewer bits), and a decoding algorithm that reconstructs the (hopefully with fewer bits), and a decoding algorithm that reconstructs the

original file or some approximation of it from the compressed original file or some approximation of it from the compressed

representation. These two components are typically intricately tied representation. These two components are typically intricately tied

together since they both have to understand the shared compressed together since they both have to understand the shared compressed

representation. We distinguish between lossless algorithms, which can representation. We distinguish between lossless algorithms, which can

reconstruct the original file exactly from the compressed file, and lossy reconstruct the original file exactly from the compressed file, and lossy

algorithms, which can only reconstruct an approximation of the original algorithms, which can only reconstruct an approximation of the original

file. file.

Page 4: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

The discrete cosine transforms is a technique for converting

a data (image pixels) into sets frequency . Therefore, The key

to the compression process discussed here is a mathematical

transformation known as the Discrete Cosine Transform

(DCT) .Among the emerging of compression techniques

standards are JPEG, for compression of still images.

Page 5: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

Before beginning, it should be noted that the pixel values of a

black-and-white image rang from 0 to 255, where pure black

is represented by 0, and pure white by 255. Since an image

comprises hundreds or even thousands of blocks of pixels, the

following description of what happens to one block is a

microcosm of the JPEG process; what is done to one block of

image pixels is done to all of them, in the order earlier

specified.

Page 6: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

For Example

Original Lena Image 256x256

Page 7: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

Now, let's start with a block of image-pixel values.

136 154 136 123 123 123 136 110

166 180 136 136 149 110 105 123

54 198 180 154 136 123 136 128

136 136 149 166 167 136 54 180

123 123 166 180 180 136 180 239

123 23 154 180 154 154 198 254

110 136 154 154 154 136 180 192

136 123 123 123 123 123 123 154

Original

Page 8: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

Now, the DCT is applied on the above matrix by using the equation:

2

)12(

2

)12(

2

1 1

0

1

0

n

jyCos

n

ixCosPCC

nD

N

x

N

yxyjiij

This yields the Following Matrix.

10 6 0 21 16- 7 11 10-

12 7 12- 18- 6 12 2- 5

3 8 12 28 0 12 11- 1-

6- 11 5- 14 12- 5- 18 30-

3 1- 15 13- 22- 5- 83- 39-

7 3- 6 31- 43- 12 60- 93-

2- 18 15- 27 32 10 108 29

12- 18- 11 30 71 20 40 1186

D

This block matrix now consists of 64 DCT coefficients, The top-left coefficient,

D00, correlates to the low frequencies of the original image block .

Page 9: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

Quantization

The 8x8 block of DCT coefficients is now ready for

compression by quantization. A remarkable and highly useful

feature of JPEG process is that in this step.

9910310011298959272

10112012110387786449

921131048164553524

771031096856372218

6280875129221714

5669574024161314

5560582619141212

6151402416101116

Q

Page 10: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

Quantization is achieved by dividing each element in the transformed image

matrix D by the corresponding element in the quantization matrix, and then

rounded to the nearest integer.

ji,

ji,ji, Q

DroundC

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 1 2-

0 0 0 0 1- 0 5- 3-

0 0 0 1- 2- 1 5- 7-

0 0 0 1 2 1 9 3

0 0 0 1 5 2 4 74

C

Page 11: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

Recall that the coefficients situated near the upper-left corner

correspond to the lower frequencies-to which the human eye is

most sensitive-of the image block. In addition , the zeros

represent the less important, higher frequencies that have

been discarded, giving rise to the lossy part of compression.

Page 12: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

Encoding

After quantization, it is not unusual for more than half of

the DCT coefficients to equal zero. JPEG incorporates

run-length coding to take advantage of this. For each non-

zero DCT coefficient, JPEG records the number of zeros

that preceded the number, the number of bits needed to

represent the number's amplitude, and the amplitude

itself. To consolidate the runs of zeros, JPEG processes

DCT coefficients in the zigzag pattern shown in figure.

Page 13: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

7.77.67.57.47.37.27.17.0

6.76.66.56.46.36.26.16.0

5.75.65.55.45.35.25.15.0

4.74.64.54.44.34.24.14.0

3.73.63.53.43.33.23.13.0

2.72.62.52.42.32.22.12.0

1.71.61.51.41.31.21.11.0

0.70.60.50.40.30.20.10.0

Zigzag sequence

Page 14: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

DecompressionReconstruction of image begins by decoding the bit stream

representing the compressed matrix C. Each element of

matrix C is then multiplied by the corresponding element of

the quantization matrix originally used.

ji,ji,ji, C*QR

The IDCT equation is:

16

1)jπ(2yCos

16

1)iπ(2xCosDCC

4

1P

7

0x

7

0yijjixy

Where

0f 1,

0f 2

1

f

C

Page 15: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

is next applied to matrix R, which is rounded to the nearest integer,

giving us the decompressed of original 8*8 image block

134 146 140 118 113 127 126 110

165 167 158 139 127 125 119 109

171 167 165 159 142 124 122 131

136 140 159 172 154 132 149 187

107 124 160 183 166 148 184 244

110 130 165 182 166 155 195 252

124 135 150 155 143 140 168 203

127 127 125 121 116 119 133 149

edDecompress

Page 16: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

136 154 136 123 123 123 136 110

166 180 136 136 149 110 105 123

54 198 180 154 136 123 136 128

136 136 149 166 167 136 54 180

123 123 166 180 180 136 180 239

123 23 154 180 154 154 198 254

110 136 154 154 154 136 180 192

136 123 123 123 123 123 123 154

Original

134 146 140 118 113 127 126 110

165 167 158 139 127 125 119 109

171 167 165 159 142 124 122 131

136 140 159 172 154 132 149 187

107 124 160 183 166 148 184 244

110 130 165 182 166 155 195 252

124 135 150 155 143 140 168 203

127 127 125 121 116 119 133 149

Decompression

Page 17: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.

Original Lena Image Reconstruct Lena Image

Page 18: The task of compression consists of two components, an encoding algorithm that takes a file and generates a “compressed” representation (hopefully with.