CS4405
JPEG Transform Coding
JPEG ¡Compression ¡Workflow
RGB YCbCr
Optional Chroma Subsample
Chroma ¡Sub-‑sampling
- 4:2:0
- Reduces ¡input ¡data ¡by ¡50%
R G B Y U V
CS4405 JPEG Transform Coding JPEG Compression Workflow RGB - - PowerPoint PPT Presentation
CS4405 JPEG Transform Coding JPEG Compression Workflow RGB Optional Chroma Subsample YCbCr Chroma Sub-sampling 4:2:0 Reduces input data by 50% R G B Y U V Chroma Sub-sampling
JPEG Transform Coding
RGB YCbCr
Optional Chroma Subsample
R G B Y U V
luminance ¡
More ¡resolution ¡in ¡Y ¡than ¡in ¡Cb ¡or ¡Cr
JPEG ¡Cb JPEG ¡Cr
JPEG ¡Y
A D C B Transform Inverse ¡Transform X0 ¡= ¡A X1 ¡= ¡B ¡-‑ ¡A X2 ¡= ¡C ¡-‑ ¡A X3 ¡= ¡D ¡-‑ ¡A A ¡= ¡X0 D ¡= ¡X3 ¡+ ¡X0 C ¡= ¡X2 ¡+ ¡X0 B ¡= ¡X1 ¡+ ¡X0
bits ¡for ¡the ¡base ¡pixel
quality
10 20 30 40 50
5 10 15 Index y
All ¡DCT ¡coefficients First ¡10 ¡DCT ¡coefficients First ¡6 ¡DCT ¡coefficients
transform ¡block ¡causing ¡blocking ¡artefacts ¡
avoided ¡without ¡having ¡to ¡encode ¡a ¡lot ¡of ¡high-‑frequency ¡ information
2-D FDCT
4 5 6 7
ire 7
’ J
1-U and 2-U discreie cosine transfoim
f2,] are the 64 sarnplcs (iJj of the Inp~tt sample block, FL,>
are the 64 DCT ~ ~ e ~ ~ c ~ e ~ ~ ~ s (x,,y) and C(x), C(y) are constants: The R ~ ~ e I I ~ ~ ~
g,,)
and coefficletilh (Fx,y)
i s illustrated in Figure 7.1.
38 (a) Original; (b) compressed and decompressed (DCT); (G) compressed and decompre-
ssed (wavckt)
each case, the compression ratio is I6x. The decompressed P E G image is clearly distorled arid 'Mocky', whereas the decompressed JFEG-2000 image is much closer to the original. Because of its good perfonnarrce in coinpressing images, the DWT is used in the new ard and is ~ i i c o ~ o r ~ ~ e d as a still image conipres-
have not yet ~ ~ n e ~ ression because there is not an easy way to e~tend wavelet compression in the temporal domain. Block-based rransforrtls such as the DCT work
well with block-based motion estimatioii arid compensation, whereas erficient, computa-
tionally tractable rnotioii-corn~ensation methodb suitable for wavelet-based cornpressjoii
for motion video c
FO
A c c o r ~ ~ ~ ~ to Equation 7.1, each of the 64 coefficients in all 64 image saniples. This means that 64 calculations, an ~ ~ ~ ~ n ~ ~ ~ a ~ ~ ~ ~ ('multiply-accumulace") must be carri total of $
4
x 64 "- 4096 i~iL~ltiply-accumu~~te
~ o r ~ i i n ~ t e l ~ , the BCT lends itself to significant s ~ m p l ~ ~ c a ~ ~ o n . weighted function of a ~ u ~ t ~ ~ ~ i ~ ~ ~ i ~ n and. DCT ~ o ~ ~ ~ c i e n ~ . A (7.3) where FY(x
=
0 to 7) are the eight coefficiertts,
JS ;ire the eight input samples and C(x)
IS a
c o n $ t ~ ~ l as before. FAST ALGORITHMS FOR THE DC'T
8 x 8 saniples (i,
j ) I-DFDCT on rows
I -D FDCT on cdtunns
8 x 8 coefficients (A, y)
1 2-D DCT via two 1-D transrorms Equation 7.1 may be rearranged as follows (Equation 4.4): where F, is the I-D represented as: CT described by Equation 7.3. In other words, the 2-
F c , y =
1
DCT of an 8 x 8 block can be calculated in two passes: a 1
graphically in Figure 7.1
1.
DCT of each row, erty is lmown as be calculated using two I-D IDCTs in a sinlilar way. The cquation Ihr roilowed by a I-D the I-D IDCT is given by Equation 7.5: This s ~ ~ ~ r ~ ~ ~ c a p ~ ~ ~ ~ ~ ~ ~ ~ ~ has two a d v a ~ ~ ~ ~ ~ s . First3 the number o C
~ r ~ t ~
~ ~
IS
reduced: each 'pass' requires 8 x 64 niultiply-accurnula~e
is 2 x 8 x 64 =
T can be readily manipulated to s ~ r e a ~ l i ~ ~ e the n ~ i ~ b e r
Practical im~l~i~entations
ise simplify calculation. and IDCT fall into two main categories:
ctmip.~tation: the DCT ~ ~ ~ , ~ ~ ~ ~
~ s
(1 - D or 2-a)
arc ~ ~ ~ r g a i ~ ~ ~ ~ ~ ~ to expicikz. the inherent syII~~etry
plicatioiis anch'or additions. This approach is appropriate for software ii~~lenientations. and ~ ~ ~ c e s s i ~ i ~
a x i i n a l r ~ ~ u l a ~ ~ ~ : the 1- ~al~ula~ions are orgkinised to regillarise the
1 1 1 general, d -U
~ ~ ~ ~ e ~ ~ ~ n ~ ~ ~ i
~ ~ (using the separable property described absvc) are less complex than 2-D iniplementations, but it i s possible to achieve higher performancc by ~anipulatin~ the 2- ~quations direclly.
1D ¡DCT ¡x ¡= ¡0 ¡to ¡7 C(x) ¡= ¡constant e.g. ¡C(2) ¡= ¡0.923880 2D ¡DCT ¡x ¡= ¡0 ¡to ¡7; ¡y ¡= ¡0 ¡to ¡7
Writing ¡a ¡2D ¡DCT ¡as ¡two ¡1D ¡DCTs
tatio~ia1 ~ e q ~ i r e ~ ~ n t s
ry of the cosine weighting fizc in the following example. CT nlay bc reduced si~nific~tly by We show how the complexity OP I
k i
xpanding Eqisation 7.6 gives (7.6j (7.7) ?'he f
~ ~ ~ w i ~ ~ properties of the cosine function can be used to simplify Equation 7.7: and
+
fi cos (F)
+ .fi
cos (i)
]
hence:
Factoring ¡and ¡ Symmetry
tatio~ia1 ~ e q ~ i r e ~ ~ n t s
ry of the cosine weighting fizc in the following example. CT nlay bc reduced si~nific~tly by We show how the complexity OP I
k i
xpanding Eqisation 7.6 gives (7.6j (7.7) ?'he f
~ ~ ~ w i ~ ~
properties of the cosine function can be used to simplify Equation 7.7: and
+
fi cos (F)
+ .fi
cos (i)
hence: FAST ALGORITHMS FOR THE DCT
1 2 3 4 5 6
~ ~ r n i n ~ t r i ~ ~
The calculation tor t
; ? hss been reduced from eight inulriplications and eight a ~ d ~ $ ~ ~ ~ s
quation 7.7) to two tnultiplic ~y~~~
a similar process t
eight ad~tiont.;lsubtractions (Equation 7.9).
FAST ALGORITHMS FOR THE DCT
1 2 3 4 5 6
~ ~ r n i n ~ t r i ~ ~
The calculation tor t
; ? hss been reduced from eight inulriplications and eight a ~ d ~ $ ~ ~ ~ s
quation 7.7) to two tnultiplic ~y~~~
a similar process t
eight ad~tiont.;lsubtractions (Equation 7.9).
Combining ¡calculations ¡(F2 ¡and ¡F6)
¡Almost ¡half ¡of ¡the ¡blocks ¡shown ¡ contain ¡skin-‑toned ¡pixels ¡with ¡very ¡ little ¡high ¡frequency ¡information If ¡an ¡image ¡is ¡broken ¡up ¡into ¡blocks ¡the ¡likelihood ¡ that ¡the ¡pixels ¡in ¡each ¡block ¡will ¡have ¡similar ¡ values ¡is ¡high ¡for ¡the ¡majority ¡of ¡the ¡blocks ¡in ¡the ¡ image
Image ¡block ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡DCT ¡Coefficients
v (vertical) u (horizontal) 7 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 6 7 5 10 15 20 25 DC coefficient (not plotted)
8
f
The ¡values ¡of ¡the ¡DCT ¡ coefficients ¡for ¡a ¡block ¡of ¡ similar ¡colours ¡are ¡not ¡ equal
Image ¡block DCT ¡coefficients
is ¡specified ¡by ¡the ¡user
4.2MB 24KB
120 108 90 75 69 73 82 89 127 115 97 81 75 79 88 95 134 122 105 89 83 87 96 103 137 125 107 92 86 90 99 106 131 119 101 86 80 83 93 100 117 105 87 72 65 69 78 85 100 88 70 55 49 53 62 69 89 77 59 44 38 42 51 58
0 black The ¡luminance ¡of ¡each ¡of ¡the ¡64 ¡pixels 255 white requires ¡64 ¡byte ¡of ¡storage ¡ 8x8 block
700 90 100 0 0 0 0 0 90 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Applying ¡DCT ¡results ¡in ¡an ¡8x8 ¡block ¡of ¡coefficients
force ¡most ¡to ¡zero
8 ¡bits ¡/ ¡ pixel 4 ¡bits ¡/ ¡ pixel 2 ¡bits ¡/ ¡ pixel
{x: x ≤ 0} {x: 0< x ≤ 1} {x: 1 < x ≤ 3} {x: 3 < x} [-1,0.5,2,3]
process ¡is ¡called ¡uniform ¡quantisation
frequencies
called ¡the ¡quantisation ¡error Xq[i,j] = Round(X[i,j]/Q[i,j]) X’[i,j] = Xq[i,j] x Q[i,j]
120 60 30 10 34 70 20 5 29 20 10 5 30 10 10 5 8 16 19 22 16 16 22 24 19 22 26 27 22 22 26 27 15 4 2 2 4 1 2 1 1 120 64 38 32 64 22 38 22 22
10 2 6
5
10 5 8 10 10 5
Reconstructed Values
X Q Xq X’
Luminance ¡Quantisation ¡Table JPEG ¡has ¡no ¡standard ¡default ¡quantizer ¡matrix ¡however ¡sample ¡matrices ¡ given ¡in ¡a ¡non-‑normative ¡appendix ¡are ¡often ¡used
Chrominance ¡Quantisation ¡Table
/ =
700 ¡90 ¡90 ¡-‑89 ¡0 ¡100 ¡0 ¡0 ¡0 ¡.... ¡0 700 90 100 0 0 0 0 0 90 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A ¡zig-‑zag ¡pattern ¡is ¡used ¡when ¡writing ¡out ¡DCT ¡coefficients
D(m,n) ¡– ¡0 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡=> ¡ ¡d(m,n) D(m,n+1) ¡– ¡D(m,n) ¡ ¡ ¡ ¡ ¡ ¡ ¡=> ¡ ¡d(m,n+1) D(m,n+2) ¡– ¡D(m,n+1) ¡ ¡=> ¡ ¡d(m,n+2) D(m,n+3) ¡– ¡D(m,n+2) ¡ ¡=> ¡ ¡d(m,n+3)
D(m,n) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡D(m,n+1) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡D(m,n+2) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡D(m,n+3) ¡ ¡
JPEG ¡Baseline
Table ¡is ¡from ¡slides ¡at ¡Gonzalez/ ¡Woods ¡DIP ¡book ¡website ¡(Chapter ¡8); Baseline ¡JPEG ¡use ¡a ¡smaller ¡part ¡of ¡the ¡coefficient ¡range ¡[-‑2047..2047]
Each ¡difference ¡category ¡is ¡a ¡ symbol ¡and ¡assigned ¡an ¡ Huffman ¡code
(0,11), ¡(0,-‑12), ¡(1, ¡-‑12), ¡(0, ¡10), ¡(0,16), ¡(0, ¡0) End ¡of ¡Block (RUNLENGTH, ¡non-‑zero ¡AC ¡coefficient)
coefficient
(0,11), ¡(0,-‑12), ¡(1, ¡-‑12), ¡ (0, ¡10), ¡(0,16), ¡(0, ¡0) (0,4) ¡: ¡11, ¡ (0,4) ¡: ¡-‑12, ¡ (1, ¡4) ¡: ¡-‑12, ¡ (0, ¡4) ¡: ¡10, ¡ (0,5) ¡: ¡16, ¡ EOB
Symbol ¡1 ¡(8 ¡bits) Symbol ¡2 ¡(varies)
Table ¡is ¡from ¡slides ¡at ¡Gonzalez/ ¡Woods ¡DIP ¡book ¡website ¡(Chapter ¡8); Baseline ¡JPEG ¡use ¡a ¡smaller ¡part ¡of ¡the ¡coefficient ¡range