Image Compression n Fundamentals Coding redundancy n The

  • Slides: 50
Download presentation
Image Compression n Fundamentals: Coding redundancy n The gray level histogram of an image

Image Compression n Fundamentals: Coding redundancy n The gray level histogram of an image can reveal a great deal of information about the image n That probability (frequency) of occurrence of gray level rk is p(rk), G 52 IIP, School of Computer Science, University of Nottingham 1

Image Compression n Fundamentals: Coding redundancy n If the number of bits used to

Image Compression n Fundamentals: Coding redundancy n If the number of bits used to represent each value of rk is l(rk), the average number of bits required to represent each pixel is n To code an Mx. N image requires MNLavg bits G 52 IIP, School of Computer Science, University of Nottingham 2

Image Compression n Fundamentals: Coding redundancy n some pixel values more common than others

Image Compression n Fundamentals: Coding redundancy n some pixel values more common than others G 52 IIP, School of Computer Science, University of Nottingham 3

Image Compression n Fundamentals: Coding redundancy n To code an Mx. N image requires

Image Compression n Fundamentals: Coding redundancy n To code an Mx. N image requires MNLavg bits n If m-bit natural binary code is used to represent the gray levels, then G 52 IIP, School of Computer Science, University of Nottingham 4

Image Compression n Fundamentals: Coding redundancy n To code an Mx. N image requires

Image Compression n Fundamentals: Coding redundancy n To code an Mx. N image requires MNLavg bits n If m-bit natural binary code is used to represent the gray levels, then G 52 IIP, School of Computer Science, University of Nottingham 5

Image Compression n Fundamentals: Coding redundancy n Variable length Coding: assign fewer bits to

Image Compression n Fundamentals: Coding redundancy n Variable length Coding: assign fewer bits to the more probable gray levels than to less probable ones can achieve data compression G 52 IIP, School of Computer Science, University of Nottingham 6

Image Compression n Fundamentals: Interpixel (spatial) redundancy n neighboring pixels have similar values n

Image Compression n Fundamentals: Interpixel (spatial) redundancy n neighboring pixels have similar values n Binary images n Gray scale image (later) G 52 IIP, School of Computer Science, University of Nottingham 7

Image Compression n Fundamentals: Interpixel (spatial) redundancy: Binary images n Run-length coding n. Mapping

Image Compression n Fundamentals: Interpixel (spatial) redundancy: Binary images n Run-length coding n. Mapping the pixels along each scan line into a sequence of pairs (g 1, r 1), (g 2, r 2), …, n. Where gi is the ith gray level, ri is the run length of ith run G 52 IIP, School of Computer Science, University of Nottingham 8

Image Compression n Example: Run-length coding Row 1: (0, 16) Row 2: (0, 16)

Image Compression n Example: Run-length coding Row 1: (0, 16) Row 2: (0, 16) encode Row 3: (0, 7) (1, 2) (0, 7) Row 4: (0, 4), (1, 8) (0, 4) Row 5: (0, 3) (1, 2) (0, 6) (1, 3) (0, 2) Row 6: (0, 2) (1, 2) (0, 8) (1, 2) (0, 2) Row 7: (0, 2) (1, 1) (0, 10) (1, 1) (0, 2) Row 8: (1, 3) (0, 10) (1, 3) Row 9: (1, 3) (0, 10) (1, 3) Row 10: (0, 2) (1, 1) (0, 10) (1, 1) (0, 2) Row 11: (0, 2) (1, 2) (0, 8) (1, 2) (0, 2) Row 12: (0, 3) (1, 2) (0, 6) (1, 3) (0, 2) Row 13: (0, 4) (1, 8) (0, 4) Row 14: (0, 7) (1, 2) (0, 7) decode Row 15: (0, 16) Row 16: (0, 16) G 52 IIP, School of Computer Science, University of Nottingham 9

Image Compression n Fundamentals: Psychovisual redundancy n some color differences are imperceptible G 52

Image Compression n Fundamentals: Psychovisual redundancy n some color differences are imperceptible G 52 IIP, School of Computer Science, University of Nottingham 10

Image Compression n Fidelity criteria n Root mean square error (erms) and signal to

Image Compression n Fidelity criteria n Root mean square error (erms) and signal to noise ratio (SNR): n Let f(x, y) be the input image, f’(x, y) be reconstructed input image from compressed bit stream, then G 52 IIP, School of Computer Science, University of Nottingham 11

Image Compression n Fidelity criteria n erms and SNR are convenient objective measures n

Image Compression n Fidelity criteria n erms and SNR are convenient objective measures n Most decompressed images are view by human beings n Subjective evaluation of compressed image quality by human observers are often more appropriate G 52 IIP, School of Computer Science, University of Nottingham 12

Image Compression n Fidelity criteria G 52 IIP, School of Computer Science, University of

Image Compression n Fidelity criteria G 52 IIP, School of Computer Science, University of Nottingham 13

Image Compression n Image compression models G 52 IIP, School of Computer Science, University

Image Compression n Image compression models G 52 IIP, School of Computer Science, University of Nottingham 14

Image Compression n Exploiting Coding Redundancy n These methods, from information theory, are not

Image Compression n Exploiting Coding Redundancy n These methods, from information theory, are not limited to images, but apply to any digital information. So we speak of “symbols” instead of “pixel values” and “sources” instead of “images”. n The idea: instead of natural binary code, where each symbol is encoded with a fixed-length code word, exploit nonuniform probabilities of symbols (nonuniform histogram) and use a variable-length code. G 52 IIP, School of Computer Science, University of Nottingham 15

Image Compression n Exploiting Coding Redundancy n Entropy n is a measure of the

Image Compression n Exploiting Coding Redundancy n Entropy n is a measure of the information content of a source. n If source is an independent random variable then you can’t compress to fewer than H bits per symbol. n Assign the more frequent symbols short bit strings and the less frequent symbols longer bit strings. Best compression when redundancy is high (entropy is low, histogram is highly skewed). G 52 IIP, School of Computer Science, University of Nottingham 16

Image Compression n Exploiting Coding Redundancy n Two common methods n Huffman coding and,

Image Compression n Exploiting Coding Redundancy n Two common methods n Huffman coding and, n LZW coding G 52 IIP, School of Computer Science, University of Nottingham 17

Image Compression n Exploiting Coding Redundancy n Huffman Coding n Codebook is precomputed and

Image Compression n Exploiting Coding Redundancy n Huffman Coding n Codebook is precomputed and static. n Compute probabilities of each symbol by histogramming source. n Process probabilities to precompute codebook: code(i). n Encode source symbol-by-symbol: symbol(i) -> code(i). n The need to preprocess the source before encoding begins is a disadvantage of Huffman coding G 52 IIP, School of Computer Science, University of Nottingham 18

Image Compression n Exploiting Coding Redundancy n Huffman Coding G 52 IIP, School of

Image Compression n Exploiting Coding Redundancy n Huffman Coding G 52 IIP, School of Computer Science, University of Nottingham 19

Image Compression n Exploiting Coding Redundancy n Huffman Coding G 52 IIP, School of

Image Compression n Exploiting Coding Redundancy n Huffman Coding G 52 IIP, School of Computer Science, University of Nottingham 20

Image Compression n Exploiting Coding Redundancy n Huffman Coding n Average length of the

Image Compression n Exploiting Coding Redundancy n Huffman Coding n Average length of the code is 2. 2. bits/symbol n The entropy of the source is 2. 14 bits/symbol G 52 IIP, School of Computer Science, University of Nottingham 21

Image Compression n Exploiting Coding Redundancy n Huffman Coding G 52 IIP, School of

Image Compression n Exploiting Coding Redundancy n Huffman Coding G 52 IIP, School of Computer Science, University of Nottingham 22

Image Compression n Exploiting Spatial/Interpixel Redundancy n Predictive Coding n Image pixels are highly

Image Compression n Exploiting Spatial/Interpixel Redundancy n Predictive Coding n Image pixels are highly correlated (dependent) n Predict the image pixels to be coded from those already coded G 52 IIP, School of Computer Science, University of Nottingham 23

Image Compression n Exploiting Spatial/Interpixel Redundancy n Predictive Coding n Differential Pulse-Code Modulation (DPCM)

Image Compression n Exploiting Spatial/Interpixel Redundancy n Predictive Coding n Differential Pulse-Code Modulation (DPCM) n Simplest form: code the difference between pixels Original pixels: 82, 83, 86, 88, 56, 55, 56, 60, 58, 55, 50, …… DPCM: 82, 1, 3, 2, -32, -1, 1, 4, -2, -3, -5, …… G 52 IIP, School of Computer Science, University of Nottingham 24

Image Compression n Exploiting Spatial/Interpixel Redundancy n Predictive Coding n Key features: Invertible, and

Image Compression n Exploiting Spatial/Interpixel Redundancy n Predictive Coding n Key features: Invertible, and lower entropy (why? ) image histogram (high entropy) DPCM histogram (low entropy) G 52 IIP, School of Computer Science, University of Nottingham 25

Image Compression n Exploiting Spatial/Interpixel Redundancy n Higher Order (Pattern) Prediction n Use both

Image Compression n Exploiting Spatial/Interpixel Redundancy n Higher Order (Pattern) Prediction n Use both 1 D and 2 D patterns for prediction 1 D Causal: 1 D Non-causal: 2 D Causal: 2 D Non-Causal: G 52 IIP, School of Computer Science, University of Nottingham 26

Image Compression n Exploiting Spatial/Interpixel Redundancy 2 D Causal: G 52 IIP, School of

Image Compression n Exploiting Spatial/Interpixel Redundancy 2 D Causal: G 52 IIP, School of Computer Science, University of Nottingham 27

Image Compression n Quantization: Widely Used in Lossy Compression n Represent certain image components

Image Compression n Quantization: Widely Used in Lossy Compression n Represent certain image components with fewer bits (compression) n With unavoidable distortions (lossy) n Quantizer Design n Find the best tradeoff between maximal compression minimal distortion G 52 IIP, School of Computer Science, University of Nottingham 28

Image Compression n Quantization n Scalar quantization Uniform scalar quantization: Non-uniform scalar quantization: 8

Image Compression n Quantization n Scalar quantization Uniform scalar quantization: Non-uniform scalar quantization: 8 24 1 2 40 248 . . . 3 4 G 52 IIP, School of Computer Science, University of Nottingham 29

Image Compression n Quantization n Scalar quantization G 52 IIP, School of Computer Science,

Image Compression n Quantization n Scalar quantization G 52 IIP, School of Computer Science, University of Nottingham 30

Image Compression n Quantization n Vector quantization and palletized images (gif format) G 52

Image Compression n Quantization n Vector quantization and palletized images (gif format) G 52 IIP, School of Computer Science, University of Nottingham 31

Image Compression n Palletized color image (gif) n A true colour image – 24

Image Compression n Palletized color image (gif) n A true colour image – 24 bits/pixel, R – 8 bits, G – 8 bits, B – 8 bits 1677216 possible colours 256 possible colours n A gif image - 8 bits/pixel G 52 IIP, School of Computer Science, University of Nottingham 32

Image Compression n Palletized color image (gif) Exploits n A true colour image –

Image Compression n Palletized color image (gif) Exploits n A true colour image – 24 bits/pixel, R – 8 bits, G – 8 bits, B – 8 bits psychovisual redundancy 1677216 possible colours 256 possible colours n A gif image - 8 bits/pixel G 52 IIP, School of Computer Science, University of Nottingham 33

Image Compression n Palletized color image (gif) (r, g, b) r 0 g 0

Image Compression n Palletized color image (gif) (r, g, b) r 0 g 0 b 0 r 1 g 1 b 1 For each pixel in the original image Find the closest colour in the Colour Table r 255 g 255 b 255 Colour Table Record the index of that colour (for storage or transmission) To reconstruct the image, place the indexed colour from the Colour Table at the corresponding spatial location G 52 IIP, School of Computer Science, University of Nottingham 34

Image Compression n Palletized color image (gif) (r, g, b) r 0 g 0

Image Compression n Palletized color image (gif) (r, g, b) r 0 g 0 b 0 r 1 g 1 b 1 How to choose the index of the colours. Record in the that colour (for storage table/pallet? or transmission) For each pixel in the original image Find the closest colour in the Colour Table r 255 g 255 b 255 Colour Table To reconstruct the image, place the indexed colour from the Colour Table at the corresponding spatial location G 52 IIP, School of Computer Science, University of Nottingham 35

Image Compression n Construct the pallet (vector quantization, k-means algorithm) (r, g, b) B

Image Compression n Construct the pallet (vector quantization, k-means algorithm) (r, g, b) B G A pixel corresponding to A point in the 3 dimensional R, G, B space R G 52 IIP, School of Computer Science, University of Nottingham 36

Image Compression n Construct the pallet (vector quantization, k-means algorithm) B G Map all

Image Compression n Construct the pallet (vector quantization, k-means algorithm) B G Map all pixels into the R, G, B space, “clouds” of pixels are formed R G 52 IIP, School of Computer Science, University of Nottingham 37

Image Compression n Group pixels that B the pallet (vector quantization, Construct arek-means close

Image Compression n Group pixels that B the pallet (vector quantization, Construct arek-means close to algorithm) each other, and replace them by one single colour G R G 52 IIP, School of Computer Science, University of Nottingham 38

Image Compression B Representative colours placed in the colour table r 0 g 0

Image Compression B Representative colours placed in the colour table r 0 g 0 b 0 r 1 g 1 b 1 G r 255 g 255 b 255 Colour Table R G 52 IIP, School of Computer Science, University of Nottingham 39

Image Compression n Discrete Cosine Transform (DCT) n 2 D-DCT n Inverse 2 D-DCT

Image Compression n Discrete Cosine Transform (DCT) n 2 D-DCT n Inverse 2 D-DCT where G 52 IIP, School of Computer Science, University of Nottingham 40

Image Compression DC component image block 2 D-DCT low frequency high frequency DCT block

Image Compression DC component image block 2 D-DCT low frequency high frequency DCT block G 52 IIP, School of Computer Science, University of Nottingham 41

JPEG Compression G 52 IIP, School of Computer Science, University of Nottingham 42

JPEG Compression G 52 IIP, School of Computer Science, University of Nottingham 42

8 x 8 x blocks JPEG Compression - 128 DCT scalar quantization zig-zag scan

8 x 8 x blocks JPEG Compression - 128 DCT scalar quantization zig-zag scan G 52 IIP, School of Computer Science, University of Nottingham 43

JPEG Compression • The Baseline System – Quantization X(u, v): original DCT coefficient X’(u,

JPEG Compression • The Baseline System – Quantization X(u, v): original DCT coefficient X’(u, v): DCT coefficient after quantization Q(u, v): quantization value G 52 IIP, School of Computer Science, University of Nottingham 44

JPEG Compression Why quantization? to achieve further compression by representing DCT coefficients with no

JPEG Compression Why quantization? to achieve further compression by representing DCT coefficients with no greater precision than is necessary to achieve the desired image quality Generally, the “high frequency coefficients” has larger quantization values Quantization makes most coefficients to be zero, it makes the compression system efficient, but it’s the main source that make the system “lossy” G 52 IIP, School of Computer Science, University of Nottingham 45

JPEG Compression Quantization is the step where we actually throw away data. Luminance and

JPEG Compression Quantization is the step where we actually throw away data. Luminance and Chrominance Quantization Table Smaller numbers in the upper left direction larger numbers in the lower right direction The performance is close to the optimal condition Quantization Dequantization G 52 IIP, School of Computer Science, University of Nottingham 46

JPEG Compression Quantization Dequantization G 52 IIP, School of Computer Science, University of Nottingham

JPEG Compression Quantization Dequantization G 52 IIP, School of Computer Science, University of Nottingham 47

JPEG Compression Exploiting Psychovisual Redundancy Exploit variable sensitivity of humans to colors: We’re more

JPEG Compression Exploiting Psychovisual Redundancy Exploit variable sensitivity of humans to colors: We’re more sensitive to differences between dark intensities than bright ones. Encode log(intensity) instead of intensity. We’re more sensitive to high spatial frequencies of green than red or blue. Sample green at highest spatial frequency, blue at lowest. We’re more sensitive to differences of intensity in green than red or blue. Use variable quantization: devote most bits to green, fewest to blue. G 52 IIP, School of Computer Science, University of Nottingham 48

JPEG Compression Exploiting Psychovisual Redundancy NTSC Video Y bandlimited to 4. 2 MHz I

JPEG Compression Exploiting Psychovisual Redundancy NTSC Video Y bandlimited to 4. 2 MHz I to 1. 6 MHz Q to. 6 MHz G 52 IIP, School of Computer Science, University of Nottingham 49

JPEG Compression Exploiting Psychovisual Redundancy In JPEG and MPEG Cb and Cr are sub-sampled

JPEG Compression Exploiting Psychovisual Redundancy In JPEG and MPEG Cb and Cr are sub-sampled G 52 IIP, School of Computer Science, University of Nottingham 50