Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed,...

55
Lossless Lossless V V ideo ideo Coding Coding Dr. Seishi Takamura Dr. Seishi Takamura NTT Corporation NTT Corporation Japan Japan Stanford EE398B April 19, 2007

Transcript of Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed,...

Page 1: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Lossless Lossless VVideoideo CodingCoding

Dr. Seishi TakamuraDr. Seishi TakamuraNTT CorporationNTT Corporation

JapanJapan

StanfordEE398B

April 19, 2007

Page 2: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 2/54

“Lossy” vs. “Lossless”“Lossy” vs. “Lossless”

Lossy image/video coding– Input != Output

– High compression (~1/10 - 1/1000)

– Possibly be“perceptually lossless”

Lossless image/video coding– Input == Output

– Low compression (~1/2 -1/3)

– “mathematically lossless”

– This is what’s meant “lossless” in this talk

Page 3: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 3/54

Is It Worthy to Sacrifice Compression Ratio?Is It Worthy to Sacrifice Compression Ratio?

Yes, for many practical reasons– Medical diagnosis, fine art archive, military purposes– Image/video analysis, automatic product examination

The observer is not a human — “perceptually lossless”does not make sense

– Contribution transmission, studio applicationsSubject to be re-encoded/edited repeatedly — coding

error accumulates, if lossyand Yes for some emotional reasons– A CG artist said, “Just do not lose even one bit from my

artwork!”– Provides an upper-bound of image quality (can feel at

ease)– Fed up with drawing R-D curves, evaluating Lagrange cost

function, subjective impairment measurement, HVS…

Page 4: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 4/54

OutlineOutline

Lossless image coding– Typical schemes and technology– FYI: Lossless image codecs comparison

Lossless video coding– Lossless variants of lossy H.264/AVC

– Using reversible transforms– Using DCT residual packing

– FYI: Lossless video codecs comparison

Summary

Page 5: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 5/54

OutlineOutline

Lossless image coding– Typical schemes and technology– FYI: Lossless image codecs comparison

Lossless video coding– Lossless variants of lossy H.264/AVC

– Using reversible transforms– Using DCT residual packing

– FYI: Lossless video codecs comparison

Summary

Page 6: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 6/54

Typical Lossless Image CodecsTypical Lossless Image Codecs

NoteAlgorithm

Context-based linear prediction + nonlinear correction

Median prediction

reversible (5,3) DWTLinear prediction

Linear prediction——

Prediction Entropy codingMethod

Huffman / Arithmetic codingCALIC

based on “LOCO” method

context-based Golomb(run-length in flat region)

JPEG-LS

Arithmetic coding (EBCOT)JPEG 2000*lossless modeHuffmanJPEG*

DEFLATE (LZ77+Huffman)PNG

LZWTIFF

up to 256 colorsLZWGIF

Bet

ter C

ompr

essi

on

Page 7: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 7/54

Prediction SchemesPrediction Schemes

Linear prediction– Fixed, encoder-optimized and online-update predictors– Using causal pixels (extrapolative DPCM)– Using non-causal pixels (interpolative DPCM)– Block transform

– Reversible DWT– Reversible DCT– R/G/B decorrelation

Median predictionMarkov model– Build a stochastic model of the image– Encode the pixel occurrence probability: Prob(x|c)– cf. minimum MSE prediction = Σx(Prob(x|c)*x)

Pixelwise residual (“Lossy plus lossless”) approach– Consider another lossy coder (e.g., JPEG) as a predictor– Entropy code the pixel-wise residual

(And motion compensation for video)

Decoded(lossy)

Originalimage

Residualdata– =

xc

x

x

Page 8: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 8/54

OutlineOutline

Lossless image coding– Typical schemes and technology– FYI: Lossless image codecs comparison

Lossless video coding– Lossless variants of lossy H.264/AVC

– Using reversible transforms– Using DCT residual packing

– FYI: Lossless video codecs comparison

Summary

Page 9: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 9/54

ARTest Codec Comparison (full-color)ARTest Codec Comparison (full-color)

2.3

2.4

2.5

2.6

2.7

2.8

2.9

3

BMFRKIMUHIC NK

ERIArH

anGeL

UHArcACE

LSPSBC DC RK

PNGCrush

LOCO

Com

pres

sion

Rat

io

Top 14 codecs out of 26Average of 627 full-color (24-bit) images, weighted by image size (#pixels)Also provides encoding/decoding time comparison

25%

[The art of lossless data compression, 2002]

Base ofJPEG-LS

Page 10: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 10/54

MRP — A Gray-Scale Lossless Image CodecMRP — A Gray-Scale Lossless Image Codec

Context-based 2D-linear prediction– M=20-56 contexts (predictors)– P=30-72 pixels from current frame– All M·P coefficients are optimized for minimum rate,

not for minimum MSE, and downloadedEncoding time: 10-25 minutes per frameDecoding time: 0.2 seconds per frame

[Matsuda et al., 2005]

Page 11: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 11/54

1.8

1.9

2.0

2.1

2.2

MRP

BMF

TMW

Glicba

wls

CALICa

JPEG-LS

CALICh

JPEG 20

00

Com

pres

sion

Rat

io

SUT Codec Comparison (gray-scale)SUT Codec Comparison (gray-scale)

http://itohws03.ee.noda.sut.ac.jp/~matsuda/mrp/

Average of 13 gray-scale (8-bit) imagesWeighted by image size (#pixels)CALICa: CALIC with arithmetic codingCALICh: CALIC with Huffman coding

9.5%

1.6%

Note: Conditions are different from previous comparison

Page 12: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 12/54

OutlineOutline

Lossless image coding– Typical schemes and technology– FYI: Lossless image codecs comparison

Lossless video coding– Lossless variants of lossy H.264/AVC

– Using reversible transforms [Takamura, ICASSP2005]

– Using DCT residual packing– FYI: Lossless video codecs comparison

Summary

Page 13: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 13/54

Lossless Coding of H.264 FRExtLossless Coding of H.264 FRExt

H.264 FRExt skips the transform and quantization

Inter/Intraprediction

4x4/8x8transform

Quanti-zation

Zigzag scan

Entropycoding

Entropy remains the same

thruFRExt

entropy reduction

entropy reduction

entropy reduction

Video

Page 14: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 14/54

Enhancement of FRExtEnhancement of FRExt

Instead of no-operation (FRExt), we apply reversible transform to reduce entropyWe compared four transforms

Inter/Intraprediction

4x4/8x8transform

Quanti-zation

Zigzagscan

Entropycoding

Reversibletransform

Aiming at entropy reduction

thruFRExt

Video

Page 15: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 15/54

Reversible Transforms TestedReversible Transforms Tested

4x4 Transform of H.264 (reversible if not quantized)Piecewise Scaled TransformReversible DCTLinear Prediction– Non-adaptive version– Adaptive version

Page 16: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 16/54

4x4 Reversible Transform

H.264 4x4 Transform4x4 Reversible Transform

H.264 4x4 Transform

Obviously reversible (if not quantized)Signal correlation is reduced…However, the signal space is expanded– 2.66 bit/pixel increment– Corrupts coding performance

⎥⎥⎥⎥

⎢⎢⎢⎢

−−−−

−−

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

−−−−

−−=

⎥⎥⎥⎥

⎢⎢⎢⎢

112121112111

1121

122111112112

1111

PONMLKJIHGFEDCBA

⎥⎥⎥⎥

⎢⎢⎢⎢

−−−−

−−

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

−−−−

−−=

⎥⎥⎥⎥

⎢⎢⎢⎢

112121112111

1121

122111112112

1111

PONMLKJIHGFEDCBA

Transform Transform coefficientscoefficients

Intra/Inter

prediction residual

Page 17: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 17/54

4x4 Reversible Transform

Piecewise Scaled Transform4x4 Reversible Transform

Piecewise Scaled Transform

Decompose H.264’s 4x4 transform into equivalent four 2x2 transforms,and compensate the expansion at each stage

1 11 –1

1 11 –1

1 11 –1

2 11 –2

1 11 –1

1 11 –1

1 11 –1

2 11 –2

2

2

2

5

2 Divide by 2 and round5 Divide by 5 and round

H.264 transform(decomposed)

Piecewise scaled transformOutput is still reversible!

Page 18: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 18/54

4x4 Reversible Transform

Reversible DCT4x4 Reversible Transform

Reversible DCT

⎣ ⎦5.0)( where)/)((

)2/)(()/)(()4/)((

21303

32102

21301

32100

+=+−−=

+−−=−+−=+++=

xxRxxCxxRX

xxxxRXCxxRxxX

xxxxRX

This is parallel to– H.264’s 4x4 transform, when C=2– Parallel to mathematical DCT, when

(recommended by the paper)We tried , 3 and 3.521+=C

21+=C

[Komatsu, Sezaki, 1996]

Page 19: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 19/54

4x4 Reversible Transform

Linear Prediction (non-adaptive)

4x4 Reversible Transform

Linear Prediction (non-adaptive)

Horizontal: Apply following transform to four rows

x0 x1 x2 x3

αΗx0 αΗx1 αΗx2

x0 R(x1 -αΗ x0) R(x2 -αΗ x1) R(x3 -αΗ x2)

Vertical: transform the columns in the same manner, using αVαH = αV = 0.7 works good for I framesαH = αV = 0.4 works good for P and B frames

Input

Output

pred. pred. pred.

Page 20: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 20/54

4x4 Reversible Transform

Linear Prediction (adaptive)

4x4 Reversible Transform

Linear Prediction (adaptive)

Optimal coefficient α is image dependentIn energy concentration sense, autocorrelation factor gives an optimal α. (But not known to the decoder unless explicitly transmitted)We estimate α from neighboring decoded blocks

ρH , ρV : horizontal and vertical autocorrelation factors in a block

ρHρV

codedblock

ρHρV

ρHρV

ρHρV

codedblock

ρHρV

ρHρV

If horizontally correlated If vertically correlated

weightedaverage

codedblock

If not correlated

default αΗ, αVweightedaverage

Highestweight

Highestweight

αΗ, αVαΗ, αV

Page 21: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 21/54

⎥⎥⎥⎥

⎢⎢⎢⎢

1000010000100001

FRExt

Transform ComparisonTransform Comparison

H.264Transform ⎥

⎥⎥⎥

⎢⎢⎢⎢

−−−−

−−

122111112112

1111

⎥⎥⎥⎥

⎢⎢⎢⎢

−−−−

−−

10/15/15/110/12/12/12/12/112/12/11

1111

⎥⎥⎥⎥

⎢⎢⎢⎢

−−−−

−−

CC

CC

/111/12/12/12/12/11/1/114/14/14/14/1

⎥⎥⎥⎥

⎢⎢⎢⎢

−−

1000100010001

αα

α

PiecewiseScaled

ReversibleDCT

LinearPrediction

Determinant

4040

11

11

1+1/1+1/CC22

11

Norm of each row

( )10,2,10,2

( )1,1,1,1

( )10/10,1,2/10,2

( )CCCC /22,1,/22,2/1 22 ++

( )222 1,1,1,1 ααα +++

The smaller, the better

More constant, the better

Non-orthogonal

Transform

Page 22: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 22/54

Simulation ConditionsSimulation Conditions

4 QCIF sequences and 5 CIF sequencesI frame performance– Encoded 100 frames (all intra)– Compared with Motion JPEG 2000 (kakadu codec)

P frame performance– Encoded 100 frames in IPPP… structure– Coding performance is obtained from 99 P frames

B frame performance– Encoded 298 frames in IBBPBBP… structure– Coding performance is obtained from 198 B frames

Page 23: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 23/54

Results (average of 9 sequences)Results (average of 9 sequences)

1

1.5

2

2.5

3

3.5

I frames P frames B frames

Com

pres

sion

Rat

io

H.264 trans.w/o quant.PiecewisescaledReversible DCTC=1+ 2Reversible DCTC=3Reversible DCTC=3.5FRExt

Linear pred.non-adaptiveLinear pred.adaptiveJPEG 2000

21+=C

Almost no compression

FRExt is not good at intra

Page 24: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 24/54

Summary for Reversible Transform CodingSummary for Reversible Transform Coding

Compared FRExt with four different reversible transforms– Non-orthogonal transform (linear prediction)

yields better compression than other orthogonal transforms

– Adaptive linear prediction works the best–12% better than FRExt (intra)–3% better than FRExt (inter)–2% worse than JPEG 2000

NoteOur method deserves yet another ~1% improvement [Sano et al, 2006]

Page 25: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 25/54

OutlineOutline

Lossless image coding– Typical schemes and technology– FYI: Lossless image codecs comparison

Lossless video coding– Lossless variants of lossy H.264/AVC

– Using reversible transforms– Using DCT residual packing [Takamura, ICIP2005]

– FYI: Lossless video codecs comparison

Summary

Page 26: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 26/54

MotivationMotivation

H.264/AVC — promising lossy video coding standard– About twice better compression than other standards– More and more H.264-compliant bit streams will be

created and distributedWhat if H.264 bit stream + additional bits = lossless?– Useful for many applications– Good interoperability with existing H.264 systems– Two-layered scalability

Existing technologies– Conventional pixel-wise residual coding: inefficient– H.264 High 4:4:4 Profile (FRExt): single-layered,

incompatibility

H.264Bit stream

EnhancementBit stream

lossless

Page 27: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 27/54

255

y

0

255

x

2D mappingA

510

B

0

-255

255

Transform

Transform and QuantizationTransform and Quantization

x y

An image(2D array of pixels)

(x,y)・・・

・・・

x (and y) : 8-bit integer

45 deg. rotated & magnified

⎥⎦

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

⎡−

=⎥⎦

⎤⎢⎣

⎡yx

vu

1111

Quantizationstep size

AB

original

Quantization bin8-b

it bord

er

Page 28: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 28/54

Recovering Original from Q-Bin Recovering Original from Q-Bin

Inverse transform

Pixel-wise residual

White grid:Impossible signal

xdif

ydif2

1

0

-1

-2-2 -1 0 1 2

20 choices

No conversion(simplified FGS)B

A1 2 3 4 5

5

4

3

2

1

25 choicesNo conversion

(general FGS)

A3.9…

4.1…

B

A lot of choices

1 2 34 5

6 7 89 10

11 12

12 Choices(optimal)

To specify original( )…

Page 29: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 29/54

H.264’s 4x4 TransformH.264’s 4x4 Transform

Above matrices are all integer-valuedTo have all 16 coefficient values (A to P) = To have exact 4x4 residual values = To have original image!

••••••••••••••••

PONMLKJIHGFEDCBA

–12–211–1–11

–2–1121111

–11–212–1–11

–2–1111121

=

Transformedcoefficients

Key Points:

Intra / Interprediction residuals

Page 30: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 30/54

Enhancement CodingEnhancement Coding

Scan all the integer grids ( , , ) within 16-dimensional quantization binΩ16=(A|A=Amin…Amax,B|B=Bmin…Bmax,…,P|P=Pmin…Pmax)using 16-nested for-loop to obtain:cases - total number of (possible candidates)index - the serial number of (original image)

Encode index using log2(cases) bits

However…Loop count (=volume of Ω16) becomes 800,000,000,000,000,000,000 when QP=12

It takes 24 million YEARS if each loop is done in 1 nsec, only for one 4x4 block!

1 2 34 5

6 7 89 10

11 12

Amin Amax

Bmax

Bmin

cases=12, index=5

Page 31: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 31/54

H.264 Basis FunctionsH.264 Basis Functions

A B C D

E F G H

K LP

11111111111111111111111111111111

−−22–111122−−22–111122−−22–111122−−22–111122

11–11–111111–11–111111–11–111111–11–1111

–1122–2211–1122–2211–1122–2211–1122–2211

JIM N O

–22–22–22–22–11–11–11–11

1111111122222222

4422–22–442211–11–22

–22–111122–44–222244

–222222–22–111111–11

11–11–111122–22–2222

22–4444–2211--2222–11

–1122–2211–2244–4422

–1122–221111−−2222–1111−−2222–11

–1122–2211

11–11–1111–111111–11–111111–11

11–11–1111

–22–1111222211–11–222211–11–22

–22–111122

11111111–11–11–11–11–11–11–11–11

11111111

–11–11–11–1122222222

–22–22–22–2211111111

2211–11–22–44–222244

4422–22–44–22–111122

–111111–1122–22–2222

–222222–2211–11–1111

11–2222–11–2244–4422

22–4444–22–1122−−2211

Page 32: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 32/54

Nifty Properties of H.264 CoefficientsNifty Properties of H.264 Coefficients

For arbitrary input, A+C is always even– One bit reduction of C, if A is known (can be ‘pack’ed

half)– So are A+I, B+J, E+G, M+O etc.

A+C+I+K is always a multiple of four.

A C1111111111111111

1–1–111–1–111–1–111–1–11

2002200220022002

+ =

4004000000004004

A C1111111111111111

1–1–111–1–111–1–111–1–11

+ KI1–1–11

–111–1–111–1

1–1–11

1111–1–1–1–1–1–1–1–1

1111

+ + =

Page 33: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 33/54

More Nifty PropertiesMore Nifty Properties

B+(C>>1)+(A>>1): Always even– If A and C are known, B can be discretized

with interval of 2.– Same for F+(E>>1)+(G>>1), E+(A>>1)+(I>>1),

G+(C>>1)+(K>>1), etc.

B–J+E–G: Multiple of 42.5(A+C)+2B+D: Multiple of 102.5(A+C+I+K)+2(E+G)+M+O: Multiple of 206.25(A+C+I+K)+5(B+E+G+J)+4F+2.5(D+L+M+O) +2(H+N)+P: Multiple of 100

00010000100001000010

0–4–40–4–404–40440440

000000000000

200020

000000000000000100

Page 34: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 34/54

Enhanced Enhancement CodingEnhanced Enhancement Coding

For each block1. Entropy-code the coefficient A using

log2(Amax−Amin+1) bits2. ‘Pack’ each of seven coefficients and

entropy-code in the same manner3. For-loop the rest eight coefficients (Ω8)

to find out index and cases4. Entropy-code index using log2(cases) bitsAt 2 and 3, numerical properties are exploited

•••M•K•I•••EDCB

PON•L•J•HGF•••••

•••••••••••••••A

pack

index, casesLoop count=400

(2·1018 times speed-up!)

Page 35: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 35/54

Quantization and BoundsQuantization and Bounds

BoundsAmin, AmaxBmin, Bmax

….Pmin, Pmax

estimationLevelslevelA … levelP

quantizationCoefficientsA ... P

levelA = (A*α + β) >> γ

x = levelA << γy = x + (1 << γ) – 1

Amin = (x – β + α – 1) / αAmax = (y – β) / α

ThenAmin <= A <= Amax

The bounds can be calculated/shared by both encoder and decoder.

Page 36: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 36/54

Coding Simulation with JM-BLCoding Simulation with JM-BL

Implemented on JM8.3 (H.264 reference codec)Two mode selection strategies regarding the base layer (BL) and enhancement layer (EL):1. OverallOpt: chooses a mode that minimizes total

(BL+ EL) bit amount2. BaseOpt: chooses a mode that RD-optimizes the

BL, no care for the EL

Compared the performance with:– Motion JPEG 2000 – FRExt-based lossless coding– Pixelwise residual entropy

BLEL

optimize

optimize

Page 37: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 37/54

Rate Trade-OffRate Trade-Off

Better

Silent, IPPQP(P)8

12

16

20

24

28

4 5 6 7 8

Rat

e (%

of u

ncom

pres

sed)

OverallOpt BaseOpt

EL

BL

Total (EL+BL)

Pixel-wise residual entropy

Page 38: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 38/54

Performance ComparisonPerformance Comparison

container news silent stefan

rate

(% o

f unc

ompr

esse

d)

Better

0

10

20

30

40

50

60

70Motion JPEG2000OverallOpt (EL/BL)BaseOpt (EL/BL)FRExt

Intra

IPP IBP IBBP IPP IBP IBBPIPP IBP IBBP

IPPIBP IBBP

Inter Inter Inter

InterIntra Intra

Intra

Page 39: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 39/54

Coding Simulation with JSVM-BLCoding Simulation with JSVM-BL

Implemented on JSVM 4 (H.264 scalable extension reference codec)14 test sequences (QCIF/CIF/4CIF, 15/30/60Hz)BL structures: III…, IPP..., IBP... and IBBBP...Other settings– FastSearch: used– ME search range: 96– Reference frame #: 1– 8x8 transform: disabled

Compared with:– Ordinary coding of Motion JPEG2000 (lossless)– Residual coding of Motion JPEG2000 (lossless) for EL– Residual entropy

Page 40: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 40/54

Bit Rate EvaluationBit Rate Evaluation

JSVMencoder

Originalvideo

JSVMdecoder

+

Entropymeasurement

Motion JPEG 2000Lossless Coder

Residualpacker

– pixel-wise residual video

Arithmeticcoder

“Proposed EL”

“Proposed BL”(III, IPP, etc.)

“EL Entropy” “MJ2K EL”

Motion JPEG 2000Lossless Coder

“MJ2K (total)”

Page 41: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 41/54

Bit Rate Breakout (CITY 4CIF, BL=III/IPP)Bit Rate Breakout (CITY 4CIF, BL=III/IPP)

0

10

20

30

40

50

60

3 5 7 9 11 13QP

Compression ratio (%)

Total (III) Base (III) Enhance (III)

Total (IPP) Base (IPP) Enhance (IPP)MJ2K

EL

BL

EL+BL

Motion JPEG2000

rate

(% o

f unc

ompr

esse

d)

Page 42: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 42/54

EL Bit Rate (BL=III…)EL Bit Rate (BL=III…)

0

5

10

15

20

25

30

3 5 7 9 11 13QPi

Bit-rate ratio (%)

MJ2K

Entropy

Proposed

rate

(% o

f unc

ompr

esse

d)

Page 43: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 43/54

EL Bit Rate (BL=IPP…)EL Bit Rate (BL=IPP…)

0

5

10

15

20

25

30

3 5 7 9 11 13QPp

Bit-rate ratio (%)

MJ2K

Entropy

Proposed

rate

(% o

f unc

ompr

esse

d)

Page 44: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 44/54

Performance ComparisonPerformance Comparison

Intra BL compression ratio is 3 points worse than Motion JPEG2000Inter BL is 7 points better than Motion JPEG2000

30

35

40

45

50

55

60

65

70

75

Bus(

CIF

@30

Hz)

(QC

IF@

15H

z)M

obile

(CIF

@30

Hz)

(QC

IF@

15H

z)C

ity(4

CIF@

60Hz

)

(CIF

@30

Hz)

Cre

w(4C

IF@

60H

z)

(CIF

@30

Hz)

Fore

man

(CIF

@30

Hz)

(QC

IF@

15H

z)H

arbo

ur(4

CIF

@60

Hz)

(CIF

@30

Hz)

Socc

er(4

CIF

@60

Hz)

(QC

IF@

30H

z)

Aver

age

MJ2K III IPP IBP IBBBPC

om

press

ion r

atio

(%)

rate

(% o

f unc

ompr

esse

d)

Page 45: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 45/54

BL:EL Bit Rate RatioBL:EL Bit Rate Ratio

~1/3 bits are spent for EL, regardless of BL GOP structure and sequence

III base/enh bit rate ratio

0%10%20%30%40%50%60%70%80%90%

100%

BUS

CIF

BUS

QC

IF

MO

BILE

CIF

MO

BILE

CIF

CIT

Y 4C

IF

CIT

Y C

IF

CR

EW 4

CIF

CR

EW C

IF

FOR

EMAN

CIF

FOR

EMAN

QC

IF

HAR

BOU

R 4

CIF

HAR

BOU

R C

IF

SOC

CER

4C

IF

SOC

CER

CIF

EnhancementBase

IBBBBP base/enh bit rate ratio

0%10%20%30%40%50%60%70%80%90%

100%

BUS

CIF

BUS

QC

IF

MO

BILE

CIF

MO

BILE

CIF

CIT

Y 4C

IF

CIT

Y C

IF

CR

EW 4

CIF

CR

EW C

IF

FOR

EMAN

CIF

FOR

EMAN

QC

IF

HAR

BOU

R 4

CIF

HAR

BOU

R C

IF

SOC

CER

4C

IF

SOC

CER

CIF

EnhancementBase

Intra (III) Inter (IBBBP)

Average EL ratio=29% Average EL ratio=32%

Page 46: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 46/54

Summary of Residual PackingSummary of Residual Packing

Scalable lossless coding having H.264-compliant BL– Drastic speed-up without losing efficiency– 20% less bits than conventional pixel-wise residual

coding– Intra BL coding (III)

– ~55% compression (compared to original)– ~3 points worse than Motion JPEG2000– 1-3% worse than Motion JPEG2000– 14% less bits than FRExt

– Inter BL coding (IPP, IBP, IBBBP)– ~44% compression (compared to original)– 5~7 points better than Motion JPEG2000– 14% more bits than FRExt

BL can be safely RD-Optimized (i.e., BaseOpt works good)Optimal EL amount: ~1/3 of total bit rate

Page 47: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 47/54

OutlineOutline

Lossless image coding– Typical schemes and technology– FYI: Lossless image codecs comparison

Lossless video coding– Lossless variants of lossy H.264/AVC

– Using reversible transforms– Using DCT residual packing

– FYI: Lossless video codecs comparison

Summary

Page 48: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 48/54

VBS — A Gray-Scale Lossless Video CodecVBS — A Gray-Scale Lossless Video Codec

Video extension of MRP (see page 10)Variable block-sized motion compensation– Quad-tree based, 32x32 to 8x8 sizes– Integer-pel accuracy

Context-based 3D-linear prediction– M=24 contexts (predictors)– P=20 pixels from current frame– Q=25 pixels from previous frame– All M(P+Q) coefficients are optimized for minimum rate, not for

minimum MSE, and downloaded for each frameEncoding time: 3-4 minutes per frameDecoding time: 0.02 seconds per frame

[Shiodera et al., 2006]

Page 49: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 49/54

SUT Codec Comparison (gray-scale)SUT Codec Comparison (gray-scale)

Average of 6 gray-scale (8-bit) video sequences (all CIF, 25 frames)

1.8

2

2.2

2.4

2.6

2.8

3

VBS FRExt VBS-intra JPEG-LS(intra)

JPEG 2000(intra)

Com

pres

sion

Rat

io

14%

34% gain due to Motion Compensation

15%

[Shiodera et al., 2006]

Page 50: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 50/54

MSU Codec Comparison (YUV 4:2:0)MSU Codec Comparison (YUV 4:2:0)

1.8

2

2.2

2.4

2.6

2.8

YULS

MSU

Snow

FFV1

x264

LOCO

Laga

rithHuff

YuvCore

PNGAlpa

ry

LZO

Com

pres

sion

Rat

io

Average of 9 YUV 4:2:0 (YV12) video sequencesAlso provides encoding time, RGB&YUV4:2:2 coding comparisonWeighted by image size (#pixels, not by #frames)

[MSU “Lossless Codecs Comparison”, Apr. 2007]

9.7%

FRExt

Note: Conditions are different from previous comparison

Page 51: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 51/54

OutlineOutline

Lossless image coding– Typical schemes and technology– FYI: Lossless image codecs comparison

Lossless video coding– Lossless variants of lossy H.264/AVC

– Using reversible transforms– Using DCT residual packing

– FYI: Lossless video codecs comparison

Summary

Page 52: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 52/54

SummarySummary

Presented lossless coding technologies– H.264 variants: FRExt extension and Scalable

coding– Introduced MRP, VBS and other state-of-the-art

lossless codec comparisons (only quantitative comparison, since the conditions are not the same)

Lossless image compression– About 1/2 for gray image– About 1/3 for RGB24 image

Lossless video compression– About 1/2.9 for both gray and YUV4:2:0 video

Page 53: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 53/54

Last But Not Least…Last But Not Least…

Drawbacks– High data rate– No rate control possible– Difficult to enclose users (re-encoding with another

codec is not a big deal)Merits– No need to locally-decode the signal– Can predict blocks/frames in parallel– No subjective viewing necessary– Independent of monitors, viewers and viewing

conditions

Page 54: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative

Takamura: Lossless Video Coding EE398B 2007.4.19 54/54

ReferencesReferences

MRPI. Matsuda et al: “A Lossless Coding Scheme Using Adaptive Predictors and Arithmetic

Code Optimized for Each Image,” Trans. IEICE (DII), Vol.J88-D-II, No.9, pp.1798-1807, Sep. 2005 (in Japanese)

The art of Lossless Data Compressionhttp://artest1.tripod.com/graphics25.htmlReversible DCTK. Komatsu and K. Sezaki: “Reversible transform coding of images,” IEICE Trans.

Fundamentals, vol. J79-A, no. 4, pp. 981–990, Apr. 1996 (in Japanese)H.264 + reversible transform (and its follower)S. Takamura and Y.Yashima: “H.264-based Lossless Video Coding Using Adaptive

Transforms,” vol.2, pp.301-304, ICASSP 2005, Philadelphia, Mar. 2005S. Sano et al: “H.264-based lossless video coding using correlation of adjacent block”,

FIT2006, J-023, 2006 (in Japanese)H.264 + residual packingS. Takamura and Y.Yashima: “Lossless Scalable Video Coding with H.264 Compliant

Base Layer,” ICIP 2005, vol.2, pp.II-754-757, Genova, Sep. 2005VBST. Shiodera et al.: “A Lossless Video Coding Scheme Using MC and 3D Prediction

Optimized for Each Frame,” Journal of the ITE, vol.60, no.7, Jul. 2006 (in Japanese)

MSU codecs comparison 2007http://www.compression.ru/video/codec_comparison/lossless_codecs_2007_en.html

Page 55: Stanford EE398B April 19, 2007 Lossless VideoCoding · Better Compression. Takamura: ... – Fixed, encoder-optimized and online-update predictors – Using causal pixels (extrapolative