I. Don’t allocate space for values that never occur
• The image has values from 0 to 255
• But only 16 levels are occupied
I. Probabilistic extension
Example
Suppose we use
1 to code the value 128
0xxxx to code other values.
If 128 occurs with probability P, these pixels we save 3*P bits;
One extra bit at 1*(1-P) of the pixels.
For this strategy and 4 bits per pixel, the break even point is 3*P - 1*(1-P) = 0 4P – 1 = 0 P = 0.25 128 occurs with high probability Use short symbols to code values that occur a lot.
II. Spatial redundancy
Some percentage of the pixels are set to random intensity levels.
Subject must set the dot intensity to the correct value.
With 1% of the pixels deleted,
observers set the value to its original 80% of the time;
With 40% deleted, they are still correct half the time
Horace Barlow
The intensity histogram
Values are distributed
fairly uniformly across the different levels.
No obvious way to code the intensities efficiently.
The spatial correlation means we can recode to reduce the range Digital value (x) D igi ta l va lue ( x+ 1)
If we code the difference we reduce the variance
DV (x) Int ens it y di ff er enc e D V ( x+ 1) – D V (x) DV (x+1) – DV(x)Difference is easier to compress:
u = x + y
v = x - y
9 bits9 bits÷÷
ø
ö
çç
è
æ
÷÷
ø
ö
çç
è
æ
-=
÷÷
ø
ö
çç
è
æ
y
x
v
u
1
1
1
1
De-correlating image data
Do you know why u,v are 9 bits and
x,y are 8 bits?
The counter-intuitive observation is that
the potential range of the transformed data may be larger than the original range;
JPEG-DCT
Best lossless compression factors are around 3-5. People want more.
What to do?
Application: JPEG-DCT
• Compress the stuff people can’t see anyway. They will never know. • This is called lossy compression
(also called perceptually lossless compression).
Discriminating contrast levels
Low contrast High contrast Low f High f Harder to see contrast differences in high than lowQuantization table
Quantization table
Quantization table
The DCT formula 7 7 0 0 ( ) ( ) 2 1 2 1 ( , ) ( , )cos cos 4 x y 16 16 C u C v x y F u v f x y u
p
vp
= = + + æ ö æ ö = ç ÷ ç ÷ è ø è øåå
Original to TransformThe DCT formula 7 7 0 0 ( ) ( ) 2 1 2 1 ( , ) ( , )cos cos 4 x y 16 16 C u C v x y F u v f x y u
p
vp
= = + + æ ö æ ö = ç ÷ ç ÷ è ø è øåå
Original to TransformDCT Basis Functions
Multiple resolution and orientation much like human vision models
8 6 6 7 6 5 8 7 7 7 9 9 8 10 12 20 13 12 11 11 12 25 18 19 15 20 29 26 31 30 29 26 28 28 32 36 46 39 32 34 44 35 28 28 40 55 41 44 48 49 52 52 52 31 39 57 61 56 50 60 46 51 52 50
Luminance table (default, q = 75)
Quantization matrix
Low spatial frequencies High spatial frequencies Quantization tableNumber of output levels is ceil(256/value)
Quantization values
Low frequencies High frequencies 128 30 10 7 6 5 8 7 7 80 9 9 8 10 12 20 13 12 11 11 12 25 18 19 15 17 29 26 2 30 5 0 28 28 9 0 0 0 0 0 44 35 5 0 0 0 0 0 48 49 2 0 0 0 0 0 3 0 0 0 0 0 0 0
After scaling and quantization, there are many zeros in the coefficient table
Compressing the JPEG coefficients
Special handling of the DC term
1. DC Term is usually large
2. It is usually similar to the value in the previous block 3. So, the DC term is encoded as the difference from the
previous block
Repeated characters:
Data: AAAABBBAABBBBBCCCCCCC Code: 4A3B2A5B7C
Run length encoding
JPEG: is mostly zeros only in high spatial frequency, so method is not effective
Data: GBCDEAFGAAAAAA Code 1: 1G1B1C1D1E1A1F1G6A
Simple encoder/decoder
If B > 0 repeat next character B times If B < 0 copy next B characters to output If B = 0, stop
100 75
50 20
Artifact visibility depends on image size physical units
Aside – For EE parties:
Phase and amplitude scrambling
Randomize Amplitude Randomize Phase
JPEG – Color
Facts you know about color perception that matter for JPEG
JPEG color - informal
Color profile
Many JPEG files embed an ICC color profile (color space). Commonly used color profiles include sRGB and Adobe RGB. Because these color spaces use a non-linear transformation, the dynamic range of an 8-bit JPEG file is
about 11 stops; see gamma curve. [However, many applications are
not able to deal with JPEG color profiles and simply ignore them.
(emphasis added, text deleted at some point).]
JPEG color space: YCbCr
0.299
0.587
0.114
0
0.1687
0.3313
0.5
128
0.5
0.4187
0.0813
128
Y
R
Cb
G
Cr
B
æ
ö æ
öæ ö æ
ö
ç
÷ ç
= -
-
÷ç ÷ ç
+
÷
ç
÷ ç
÷ç ÷ ç
÷
ç
÷ ç
-
-
÷ç ÷ ç
÷
è
ø è
øè ø è
ø
Default luminance table (q=75)
Y = 0.299R + 0.587G + 0.114B
Cb = -0.1687R - 0.3313G + 0.5B + 128 Cr = 0.5R - 0.4187G - 0.0813B + 128
JPEG Color: YCbCr
Target is an RGB image
Y = 0.299 R + 0.587 G + 0.114 B I = 0.596 R - 0.275 G - .321 B Q = 0.212 R - 0.523 G + .311 B
For transmission in the US, the image was converted to YIQ Transformed to
I Q
Y Q
Multiscale representations
Pyramid
construction
principles
space int ens it y Original signalPyramid
construction
principles
Pyramid
construction
principles
Pyramid
construction
principles
Gaussian and Laplacian Pyramids
Blur and sub-sample
Upsample, error
Pyramids
Gaussian
The pyramids have more coefficients than the original
0
1
1
1
4
1
...
4
4 16
3
n
n
¥
=
æ ö = + +
=
ç ÷
è ø
å
Number of coefficientsCoefficient variance is smaller in Laplacian pyramid
Gaussian pyramid coefficients