ece-c490 winter 2004 image processing architecture
DESCRIPTION
ECE-C490 Winter 2004 Image Processing Architecture. Lecture 4, 1/20/2004 Principles of Lossy Compression Oleh Tretiak Drexel University. Review: Lossless Compression. Compression: Input is a sequence of discrete symbols Main theoretical tool: Entropy Technology: Coding Methods - PowerPoint PPT PresentationTRANSCRIPT
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 1Lecture 4
ECE-C490 Winter 2004 Image Processing Architecture
Lecture 4, 1/20/2004
Principles of Lossy CompressionOleh Tretiak
Drexel University
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 2Lecture 4
Compression: Input is a sequence of discrete symbols Main theoretical tool: Entropy
Technology: Coding Methods Huffman codes
Variable length code words, high probability symbols get short code words
Ideally, length of code word should be -log2pi
Arithmetic codes Many symbols translate to many code bits Each input symbol produces -log2pi
Other codes: Golomb-Rice
Review: Lossless Compression
H =− pi log2 pii∑
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 3Lecture 4
Successful preprocessing can reduce per/symbol entropy Example: Run-length encoding Example: Prediction on the basis of past values
Review: Coder Structures
SignalPreprocessorEntropy CoderData
High entropy Low entropy
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 4Lecture 4
Review: Coder Design Strategies Fixed encoder
Example: ITU-T, Rec. T.4 (Group 3), Rec. T.6 (Group 4) Excellent compression on text documents of fixed resolution Simple system
Adaptive encoder Example: JBIG
Adaptive predictor on basis of context Arithmetic coding with p estimated from documents Superior performance over a large range of documents
ContextpixelsPixelbeing
predicted
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 5Lecture 4
Review: Coder Designs Example: Lossless JPEG
Prediction on basis of context 8 prediction rules, choose the best one
Selection Value Prediction
0 No prediction1 a2 b3 c4 a+b-c5 a+((b-c)/2)6 b+((a-c)/2)7 (a+b)/2
abcx
Prediction context
Available Prediction Rules
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 6Lecture 4
This Lecture Lossy Compression
Tradeoff between quality and number of bits Bit reduction Resolution reduction Quantizers
Rate distortion theory
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 7Lecture 4
Review: Lossless Compression of Images
Can get quite good compression of graphics images Lossless compression of gray-scale images (JPEG) is ~ 2 What to do?
Keep trying Give up Take another approach
Lossy Compression
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 8Lecture 4
Lossy Compression Ideas Tradeoff between bits and quality
Name of the game: Large reduction in bits at virtually no loss in quality
Theoretical tool Shannon Rate-Distortion Theory
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 9Lecture 4
Quality - Rate Tradeoff Given: 512x512 picture, 8 bits per pixel
Bit reduction Fewer bits per pixel Fewer pixels Both
Issues: How do we measure compression?
Bits/pixel — does not work when we change number of pixel Total bits — valid, but hard to interpret
How do we measure quality? RMS noise Peak signal to noise ratio (PSR) in dB Subjective quality
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 10Lecture 4
Reduced bits/pixel Keep b most significant bits Compression = 8/b Distortion: o(i, j) original picture, r(i, j) reduced picture,
we define the noise as RMS error:
Peak Signal to Noise Ratio (PSNR) = 20log10(255/)
n(i , j ) =r(i, j) –o(i, j)
s =
1HV
(n(i, j ))2
j =1
V
∑i =1
H
∑
Bits 8 7 6 5 4 3 2 1Compression 1.00 1.14 1.33 1.60 2.00 2.67 4.00 8.00Error 0 0.7 1.22 2.35 12.5 22.5 35.5 51.5PSNR, db 51 46 41 26 21 17 14
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 11Lecture 4
Reducing bits per pixel.Upper row, left to right:8, 4, 3 bits per pixel. Lower row, left to right:2, 1 bits per pixel. With 5, 6, and 7 bits per pixel the image is almost the same as 8 bits.
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 12Lecture 4
Loss vs. Bit Rate
0
10
20
30
40
50
60
0 2 4 6 8
bits/pixel
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 13Lecture 4
Resolution Reduction Start with 512x512 8 bit image Sample over a WxW point grid, keep 8 bits per pixel r(i, j) is interpolated to a 512 x512 grid Compression = (512/W)2
n(i, j) = r(i, j) - o(i, j) Compute RMS Noise and PSNR
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 14Lecture 4
512 382
256 181
128
Resolution reduction. Upper left is full resolution (512x512 pixels). Lower right image has 1/8 of the pixels, Compression = 8.
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 15Lecture 4
Difference Between Compressed and Original
Difference between 128x128 (16 fold compression) and original image
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 16Lecture 4
Quantitative PerformanceResolution 512 362 256 181 128Compression 1 2 4 8 16RMS error 0 2.7 4.08 7.29 7.75PSNR 40 36 30.9 30.4
PSNR
0
5
10
15
20
25
30
35
40
45
0 100 200 300 400Resolution
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 17Lecture 4
Comparison, Bit and Pixel Reduction
0
10
20
30
40
50
60
0 1000000 2000000
Total bits in image
SubsampleDrop bits
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 18Lecture 4
Conclusion and Questions For this image, resolution reduction is a much more effective
compression method than bit reduction 8-fold reduction in bits at 30 dB PSNR with subsamplng 2.67-fold reduction bits at 29 dB PSNR with bit reduction
What is the best combination of sampling and bits? Can entropy coding help? Is there a theory that can guide us?
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 19Lecture 4
Theory Theory tells us that the data we encode should be statistically
independent In a picture, adjacent pixels are correlated.
Shannon’s rate-distortion theory provides a way of finding the tradeoff between rate (total bits per image) and distortion (rms. error)
Image should be transformed (preprocessed) so that statistically independent samples are encoded
Correlated images (with low detail) can be compressed more than uncorrelated images.
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 20Lecture 4
Typical Rate-Distortion Functions
Rate is in bits per image, or bits per time Distortion is 1/(rms. error)
0.0001
0.001
0.01
0.1
10 5 10
Rate (bits)
IndependentCorrelated
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 21Lecture 4
Information Theory of Continuous Sources
Quantizers Decorrelation and Bit Allocation Rate-Distortion Theory DCT (Discrete Cosine Transform)
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 22Lecture 4
Quantizer: The Basics Given: 8 bit gray value samples, 0 ≤ data ≤ 255 Task: Keep 4 bits per sample Method: Shift 4 bits to right (divide by 24 = 64)
This is called quantization Quantization step S = 64 All values betwee 0 and 63 are mapped to 0, values from 64 to 127
are mapped to 1, etc Restoring data: Multiply by 24 = 64 and add 32
This is called dequantization What used to be between 0 and 63 is now at 32, data values
between 64 and 1
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 23Lecture 4
Example of quantization
0
20
40
60
80
100
120
140
160
Quantizer inputDequantizer output
Quantization with S = 20. Note that the dequantizer output is typically not equal to the input!
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 24Lecture 4
Quantizer Performance Questions:
How much error does the quantizer introduce (Distortion)? How many bits are required for the quantized values (Rate)?
Rate: 1. No compression. If there are N possible quantizer output values, then it takes
ceiling(log2N) bits per sample. 2(a). Compression. Compute the histogram of the quantizer output. Design Huffman
code for the histogram. Find the average lentgth. 2(b). Find the entropy of the quantizer distribution 2(c). Preprocess quantizer output, ....
Distortion:Let x be the input to the quantizer, x* the de-quantized value. Quantization noise n = x* - x. Quantization noise power is equal to D = Average(n2).
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 25Lecture 4
Quantizer: practical lossy encoding
Quantizer Symbols
x — input to quantizer, q — output of quantizer,S — quantizer step
Quantizer:q = round(x/S)
Dequantizer characteristicx* = Sq
Typical noise power added by quantizer-dequantizer combination: D = S2/12
noise standard deviation = sqrt(D) = 0.287SExample: S = 8, D = 82/12 = 5.3,
rms. quatization noise = sqrt(D) = 2.3 If input is 8 bits, max input is 255. There are 255/8
~ 32 quantizer output values PSNR = 20 log10(255/2.3) = 40.8 dB
Δxq
Δx*q x* =Dq Quantizer characteristic
Dequantizer characteristic
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 26Lecture 4
Rate-Distortion Theory
Probabilistic theory, developed by Claude Shannon in 1949 Input is a sequence of independent random variables, output
are lossy (distorted) reproduction Joint probability density function p(x, y) Distortion: D =E[(X–Y)2] (mean squared error, noise power),
Rate-distortion function
X i YiEncoderDecoderBits/sample
I(X ,Y ) = log2∫∫p(x,y)
p(x)p(y)dxdy
R(D) = minover p(y|x)with D fixed
I(X,Y )
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 27Lecture 4
Rate-Distortion Theorem When long sequences (blocks) are encoded, it is possible to
construct a coder-decoder pair that achieves the specified distortion whenever bits per sample are R(D) +
Formula: X ~ Gaussian random variable, Q = E[X2] ~ signal power
D = E[(X–Y)2 ] ~ noise power
p(x ) =1
2πQ(exp −x2 / 2Q )
R =12
log2QD
D ≤Q
0 D >Q
⎧ ⎨ ⎪
⎩ ⎪
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 28Lecture 4
Rate-Distortion Function for Gaussian Distribution
‘Theoretical’ plot ‘Practical’ plot
Gaussian Rate-Distortion Function
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
0 0.5 1 1.5 2
D/Q
R - bits per sample
Gaussian Rate-Distortion Function
0
1
2
3
4
5
-10 0 10 20
SNR = 10log10(Q/D)
R (bits)
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 29Lecture 4
Rate - Distortion, in words
Q - actual signal power (size) D - specified distortion power D > Q (specified distortion bigger than signal)
R = 0, send nothing, actual distortion = received - sent distortion power = Q
D < Q (specified distortion less than signal Coded bits per sample = 0.5 log2(Q/D)
This formula applies for coding statistically independent symbols!
R =12
log2QD
D ≤Q
0 D >Q
⎧ ⎨ ⎪
⎩ ⎪
Image Processing Architecture, © 2001-2004 Oleh Tretiak Page 34Lecture 4
Basic Solution If the total distortion is small,
Make Di = D/n
Ri = 0.5 log2 (Qi /Di) = 0.5 log2(nQi /D)
This holds as long as Qi ≥ D/n for all i