A new method for lossless and near lossless image...

31
LOCO A new method for lossless and near lossless image compression Nimrod Peleg Update: Dec. 2003

Transcript of A new method for lossless and near lossless image...

Page 1: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

LOCOA new method for lossless and

near losslessimage compression

Nimrod PelegUpdate: Dec. 2003

Page 2: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Credit...• Suggested by HP Labs, 1996• Developed by: M.J. Weinberger, G. Seroussi

and G. Sapiro,

“LOCO-I: A Low Complexity, Context-Based, Lossless Image Compression Algorithm”,

IEEE Proceedings of Data Compression Conference, pp. 140-149, 1996

Page 3: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

General Block DiagramDigital SourceImage Data

Context Modeling Prediction

Run Mode

ErrorEncoding

CompressedData

Page 4: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Context Based Algorithm

• An efficient coding needs a statistical model, for a good prediction of pixel value

• The statistical distribution of a pixel is predicted according to the previous pixels

• The best distribution for coding is minimum entropy distribution

• To achieve it, each pixel is assigned to a “context” (728 context types in LOCO)

Page 5: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Prediction

• After context definition, a simple predictionis activated.

• The predictor is NOT context dependent, but same for all contexts.

• It’s a simple and effective edge detector, based on 3 gradients.

• Prediction error is calculated between predicted and “real’ pixel value.

Page 6: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Error Coding• Basic assumption: for each context, a

statistical information is available.• A Geometric distribution is assumed for the

prediction error, and LOCO uses 2 parameters for each context: Average and Decay factor.

• LOCO uses a Golomb-Rice entropy coding, which is optimal for two-sided geometric distribution (it’s a 1 parameter Huffman like method).

Page 7: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

The Golomb-Rice technique is simple, low-complexity and efficient:– Huffman-like complexity– Almost Arithmetic coding efficiency

Page 8: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Run Mode• When all local gradient are zero, we can

assume that it’s a “smooth” area in the image.• In this situation we skip the prediction and the

prediction error coding stages.• We go on with the “run-mode” until the

condition x=b is no more TRUE.• This process saves lots of bitsfor long runs. c a d

b x

Page 9: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression
Page 10: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

General SchemeGeneral Scheme

ContextModelingContext

Modeling

Entropy Coding

Single framesPrediction

Error

StatisticalParameters

To Network

Compressed BitStream

PredictionPrediction

Page 11: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Context ModelingContext ModelingEvery pixel is assigned to a context

based on locally calculated parameters.

Why ?

Prediction errors for pixels in same context, have the same statistical distribution.

Page 12: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

The assumption is The assumption is --The prediction error is distributed as a two sided geometric distribution.

-300 -200 -100 0 100 200 3000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

• The extinction factor is context dependent.• There is systematic bias for every context.

Page 13: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Calculating the context numberCalculating the context numberThere is a tradeoff between the number of contextsand the quality of the estimated statistics for each context.

In the LOCO algorithm:There are 728 contexts created by using the localGradients:

c a db x

D1= d-aD2= a-cD3= c-b

Page 14: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

PredictionPrediction

The Loco predictor is “casual”, it uses nearby pixels which already have been scanned

Pxa ba b

a b c=

+ −

min( , )max( , )

c a bc a botherwise

≥≤

max( , )min( , )c a d

b x

Page 15: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

The principle :The principle :

1

15

2

1

15

2100

150

200

250

c

b

a

a

c

b

x

The assumption is :‘x’ should be onthe same plane

created by a, b and c .

Page 16: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

For example :For example :

1

15

2

1

15

2100

150

200

250

c

ba

Here, the lowest value x can get is the value of b(from what we “have”).

Pxa ba b

a b c=

+ −

min( , )max( , )

c a bc a botherwise

≥≤

max( , )min( , )

Page 17: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Why not take the Why not take the AverageAverage ??

x a b c=

+ +3

1

15

2

1

15

2100

150

200

250

c

b

a

Page 18: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Let’s take a look on this case -When c is very close to a . . .

1

15

2

1

15

20

50

100

150

c

b

a

x a bavg ≈

+23

Px = b

But,

Page 19: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Prediction ExampleOriginal Image Predicted Image (SNR=25.3dB

Page 20: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression
Page 21: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

The QuantizerThe Quantizer

The gradients are quantized by a 9 level quantizer

T3 T2 T1 0 T1 T2 T3

( Q1,Q2,Q3 )

The context number - Q

Page 22: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Entropy CodingEntropy CodingGolomb-Rice is an optimal entropy coder for geometric distribution

Golomb - Rice Codes• Does not require tables (vs. Huffman)• One parameter only: k

msb

k bitsBy binary presentation

8-k bitsBy unary presentation

Page 23: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Golomb-Rice coding example

0000 1110

k = 2

Let’s take the number: x=14

Unary presentation of 112 (= 310) = 0 0 01

UnaryCode 0 0 0

Separatingone

Binary presentation - 1 01

X/2K = 3 with remainder 2 BinaryCode

1 0

The BitStream

Page 24: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Context parameters :

• K - calculated from sum of error magnitudes • Bias - calculated from sum of errors

Page 25: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Run mode

A special mode which allows efficient compressionof a sequence of pixels with same value.

For example :

Page 26: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

In Lossy ModeLossyLossy ModeMode

Maximal allowed restoration error per pixel = 0 NEAR

The method :The prediction error is quantized by a 2Near + 1step quantizer .

Prediction Error2Near + 1

Prediction Error

Page 27: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

And the profit is . . .

-300 -200 -1000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

• Narrower geometric distribution

Shorter Golomb-Rice Codes

• Spending more time in Run-Mode

Page 28: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

0 5 10 15 20 25 300

5

10

15Compression ratio vs. Near

ratio

: 1

0 5 10 15 20 25 3010

20

30

40

50SNR vs. Near

SNR [

dB]

Page 29: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Explanation (last graph: Lena for different Near values)

ש בערכים נ מוכים העלייה ביחס , נית ן לראות

או לם בערכים , Nearהדחי סה לינ יא רית עם כמעט ואי ן שיפור ביחס Nearגבוהים ש ל

מאבד את LOCOהי א ש ה , הס יבה לכך. הדחי סה ולכן מ אבד את , גבוהים Nearבערכי Contextsה

ג ם א י כות הת מ ונ ה הדחו סה בערכים . יעילותו

כפי שנית ן לראות מגרף , הגבוהים ירודה ביו תר

.SNR ה

Page 30: A new method for lossless and near lossless image compressioncs.haifa.ac.il/~nimrod/Compression/JPEG/J9loco2003.pdf · A new method for lossless and near lossless image compression

Different Near values compression

Near = 3 Near = 10