300 likes | 410 Views
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
E N D
ECE-C490 Winter 2004Image 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 • 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
High entropy Low entropy Review: Coder Structures • Successful preprocessing can reduce per/symbol entropy • Example: Run-length encoding • Example: Prediction on the basis of past values
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
Review: Coder Designs • Example: Lossless JPEG • Prediction on basis of context • 8 prediction rules, choose the best one Prediction context Available Prediction Rules
This Lecture • Lossy Compression • Tradeoff between quality and number of bits • Bit reduction • Resolution reduction • Quantizers • Rate distortion theory
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
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
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
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/s)
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.
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
512 382 128 Resolution reduction. Upper left is full resolution (512x512 pixels). Lower right image has 1/8 of the pixels, Compression = 8. 256 181
Difference Between Compressed and Original • Difference between 128x128 (16 fold compression) and original image
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?
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.
Typical Rate-Distortion Functions • Rate is in bits per image, or bits per time • Distortion is 1/(rms. error)
Information Theory of Continuous Sources • Quantizers • Decorrelation and Bit Allocation • Rate-Distortion Theory • DCT (Discrete Cosine Transform)
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
Example of quantization Quantization with S = 20. Note that the dequantizer output is typically not equal to the input!
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).
Quantizer: practical lossy encoding • Quantizer • Symbols x — input to quantizer, q — output of quantizer,S — quantizer step • Quantizer: q = round(x/S) • Dequantizer characteristic x* = Sq • Typical noise power added by quantizer-dequantizer combination: D = S2/12 noise standard deviation s = sqrt(D) = 0.287S Example: 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 Quantizer characteristic Dequantizer characteristic
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
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) + e. • Formula: X ~ Gaussian random variable, Q = E[X2] ~ signal power • D = E[(X–Y)2 ] ~ noise power
Rate-Distortion Function for Gaussian Distribution ‘Theoretical’ plot ‘Practical’ plot
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!
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