1 Image Compression Lossy Compression and JPEG Review • Image Compression – Image data too big in “RAW” pixel format – Many “redundancies” – We would like to reduce redundancies • Three basic types – Coding Redundancy – Interpixel Redundancy – Psycho-visual Redundancy
25
Embed
Image Compression - Vis Centerryang/Teaching/cs635-2016spring/Lectures/11...Image Compression Lossy Compression and JPEG ... Discrete Cosine Transform ... Code for generating the Quantization
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
Image Compression
Lossy Compressionand JPEG
Review
• Image Compression– Image data too big in “RAW” pixel format– Many “redundancies”– We would like to reduce redundancies
• Three basic types– Coding Redundancy– Interpixel Redundancy– Psycho-visual Redundancy
2
Review• Compression for Coding Redundancies
– Variable Length Coding• Huffman Encoding• Use smaller “codes” for more probable symbols
• Compression for Interpixel Redundancies– Introduce Mapping
• Often from pixel space to non-visual format• Run-Length-Encoding (RLE)
– Predictive Coding• Use previous pixel to predict the next pixel• Encode the error
Review
Sourceencoder
Channelencoder Channel Channel
decoderSourcedecoder
f(x,y) f’(x,y)
f’(x,y)Mapper Quantizer Symbol
EncoderSymboldecoder
InverseMapperf(x,y)
Loss
3
Objective Fidelity Criteria• Commonly used fidelity criteria is
– mean-square signal-to-noise ratio defined as:
∑∑
∑∑−
=
−
=
−
=
−
=
−= 1
0
1
0
2
1
0
1
0
2
)],(),('[
),('
M
x
N
y
M
x
N
yms
yxfyxf
yxfSNR
f(x,y) is originalf’(x,y) is compress/decompress
Subjective Fidelity Criteria• Human-based criteria• Usually side-by-side comparison
4
Lossy Compression• Compromise accuracy
– That is, we will allow for “error”– Distortion
• In exchange for increased compression– If the resulting distortion can be tolerated– Then we can gain substantial compression
• Exploit psycho-visual Redundancy– Our eye is less sensitive to high-frequencies– Can can “throw” away a lot of detail and image
looks the same
Lossy Compression
5
Lossy vs. Lossless
• Lossy Schemes– Image is still recognizable
• 30:1 Compression ratio– Image is “virtually” indistinguishable
from original• 20:1 - 10:1 Compression ratio
• Lossless– Rarely get more than 3:1 reduction
Lossy Schemes
• Principal difference from lossless
• Introduction of “quantization”– Quantization maps values to limited
range– The more the quantization
• More Compression• (and more distortion)
6
Lossy Predictive Coding• Predictive Coding Scheme
– Based on lossless predictive coding scheme
– Recall that lossless prediction was:• e = f’ - f
– f is pixel– f’ is the predicted pixel– e is the error
Loss Predictive Coding• Error will be quantized to a limited
range– e = f’ – f– e’ = e/q– f’’ = f’+e’ (resulting pixel with error)
• f is a pixel• f’ is the predicted pixel• e’ is the quantized error• f’’ is the resulting pixel
– note, we will need to use f’’ in the predictor
7
Lossy Predictive Coding Model
• Error is quantized• Predictor uses lossy pixels (f’’) to predict f’
Predictor
∑−
+f(x,y)
e’(x,y)en e’n
Quantizer
∑−
+f’f’’= f’+e’
Lossy/Lossless Comparison
Predictor Nearest integer
∑−
+f(x,y)
f’(x,y)
e(x,y)
Lossless
Lossy
Predictor
∑−
+f(x,y)
e’(x,y)en e’n
Quantizer
∑−
+f’ f’’= f’+e’
8
Delta Modulation• Simple and well-known technique
• Predictor = f’n = αf’’n-1
+γ en > 0• e’n =
-γ otherwise
• where γ is a constant
Example 1-D scanline
γ = 6.5
9
2D Image
γ = 6.5Originalα = 1.0
roughly 8:1Compression
Transform Coding• Predictive coding operates directly on
pixels
• Transform coding– Uses a reversible, linear transform (FT for
example)– to map the pixels to new coefficients– quantizes the coefficients– Compresses these further (RLE, Variable
Length Coding )
10
Typical Transform Coding Scheme
f(x,y) Constructnxn
subimages
ForwardTransform Quantizer
“De-quantizer”InverseTransform
Mergenxn
subimagesf’(x,y)
Other
Other
CompressedImage
CompressedImage
Idea behind Transform Coding
• Transform pixels to a new “space”
• The new space provides a more compact representation of the information– Signal Power “Packing”
• Less susceptible to quantization
11
Remember this example
Original 2D Fourier Coefficients
F(u,v)
8
18 43
78 153
Transform Coding
• Transform Selection– Discrete Fourier Transform– One solution
• Discrete Cosine Transform– Like FT– But, no imaginary component– DCT shown to have better power
“packing” abilities over DFT
12
Discrete Cosine Transform(Forward DCT)
2
1
)(
2)12(cos
2)12(cos),()()(),(
1
0
1
0
N
Ni
Nvy
NuxyxfvuvuC
N
x
N
y
=
⎥⎦⎤
⎢⎣⎡ +
⎥⎦⎤
⎢⎣⎡ +
= ∑∑−
=
−
=
α
ππαα
for i=0
for i=1, . . ., N-1
Discrete Cosine Transform(Inverse DCT)
2
1
)(
2)12(cos
2)12(cos),()()(),(
1
0
1
0
N
Ni
Nvy
NuxvuCvuyxf
N
u
N
v
=
⎥⎦⎤
⎢⎣⎡ +
⎥⎦⎤
⎢⎣⎡ +
= ∑∑−
=
−
=
α
ππαα
for i=0
for i=1, . . ., N-1
13
DCT vs. FFTWhy DCT and not FFT?
DCT behaves better under quantization. . . (and no complex math)
+I(u)
Original Pixel Values
Subimage size (n=?)
• Power of 2– Allows “fast nlogn” algorithms to be applied
• As the size n increases– Level of compression achievable increases– Level of computational complexity increases
• Empirical testing showed– n=8 or n=16 gives the best overall performance– (testing performed back in the early 90s)– (today’s compute power can probably handle larger n)
f(x,y) Constructnxn
subimages
ForwardTransform Quantizer Other
14
2D 8x8 DCT Basis
2D DCT using 8x8 block
Transformed block is a linear combination of these basis
1 coefficient for eachbasis
Example of compression with DCT
• matlab– dctdemo
• divide image into 8x8 blocks– quantization in this example means
dropping coefficients– coefficients are dropped based on their
magnitude |C(u,v)|
15
JPEG Compression• Story of JPEG
– Joint Photographic Expert Group• International Organization for Standards
(ISO)– 1988: ISO got together a group of experts to
develop a good image compression scheme• Geared towards photographs of natural imagery• Color and monochrome• Easy to use (spin-dial quality control)
– Through empirical testing, the following scheme proved to be the best
– Standardized in August 1990
JPEG Encoding Scheme
f(x,y)Divided into8x8 blocks
FDCT(Forward DCT)on each block
Quantize DCT coefficientsvia
Quantization “Table”
C’(u,v) = round(C(u,v)/T(u,v))
“Zig-zag” Order Coefficients
RLEAC Vector
0Differentialcoding DC component
Huffman Encode
JPEG bitstream
T(u,v)
f(x,y) - 128(normalize between –128 to 127)
16
JPEG Decoding Scheme
f(x,y)Divided into8x8 blocks
IDCT(Inverse DCT)on each block
De-quantize DCT coefficients
via Quantization “Table”C(u,v) = C’(u,v)*T(u,v)
T(u,v)
“Zig-zag” order Coefficients
RLE (decode)AC Vector
0Differentialdecoding DC component
Huffman decode
JPEG bitstream
f(x,y) + 128
Example Quantization Table
Example via matlab
T(u,v) =
DC (low)
AC (higher)
We are more sensitive to low-frequenciesQuantize the high-frequencies more
Usage:C(u,v) is DCT of f(x,y) 8x8 blockC’(u,v) = C(u,v) ./ T(u,v)