Vous êtes sur la page 1sur 53

ECE-G311

2-D Signal and Image Processing

Image Coding-II
Outline
z Waveform Coding
„ Pixel Coding
‹PCM
„ Entropy Coding
‹Huffman
‹Group Coding
‹LZW Coding
„ Predictive Coding
‹Delta Modulation
‹Line-by-Line DPCM
‹2D DPCM
‹Lossless DPCM

ECE G311 – Image Coding-II Slide 2 of 36


Coding Techniques
z Image coding schemes can be categorized in the following general
groups:
„ Waveform Coding: Coding of image intensities.
‹Pixel Coding: PCM, Lemple-Ziv coding, Huffman coding,
Facsimile Coding, Bit-plane Coding.
‹Predictive Coding: Line-by-line DPCM, 2-D DPCM, Tree
encoding.
„ Transform Coding: Coding of transform coefficients.
‹Zonal Coding
‹Threshold Coding
„ Image Model Coding: Coding of image model coefficients.
„ Other Techniques:
‹Hybrid Coding
‹Adaptive Coding

ECE G311 – Image Coding-II Slide 3 of 36


Waveform Coding
z In this approach, the coding is performed on spatial-domain image
values which are assigned a codeword.
z There are three techniques:
„ Pixel-coding:
‹ In this techniques. Each pixel is processed independently.
‹ Generally speaking, this techniques is also used to achieve
loss-less coding.
„ Predictive coding:
‹ In this technique, correlations among a group of pixels is
used to remove redundant data.
‹ The difference or the new information is then coded.
„ Binary Image coding:
‹ This technique is used in facsimile (or fax) transmission.
‹ Presence of a large amount of white or black space is used
to compress data.
ECE G311 – Image Coding-II Slide 4 of 36
Pixel Coding
z In this approach, each pixel is assumed to be an independent
random variable with a prescribed probability.
z Let the number of gray-levels in an image be equal to L, i.e.,
x0 , x1 ,K , xL −1 : Gray-levels
with probabilities:
Pr( x0 ) = p0 , Pr( x1 ) = p1 ,K , Pr( xL −1 ) = pL −1
z Basic Principle:
Assign code-words of length li to each level value xi so that the
average bit-rate
L −1
R ∑ pi l i
is minimum. i =0

ECE G311 – Image Coding-II Slide 5 of 36


Pulse Code Modulation (PCM)
z Let the gray-levels be equally likely, i.e.,
p0 = p1 = L = pL −1 with L = 2B
z Then the entropy H is given by
L −1 L −1 L −1
1 ⎛ 1⎞ 1 ⎛ 1 ⎞ 1
H = −∑ log 2 ⎜ ⎟ = − ∑ log 2 ⎜ B ⎟ = ∑ B = B
L ⎝ L⎠ L ⎝2 ⎠ L
0 0 0
z Thus we can assign B-bit words to each level and achieve the
average bit-rate R equal to H.
z This results is a fixed-length (or block) coding and is the classic
PCM technique.
z When the gray-level probabilities are not equally likely, then
entropy H is not an integer and PCM is not the best approach.
z However, for practical considerations, images sometimes are
stored as B (= 8) bits/pixel.
ECE G311 – Image Coding-II Slide 6 of 36
Entropy Coding
z What we need a variable length coding technique that can assign
a uniquely decodable (prefix-free) code-words to achieve bit-rate
R very close to the entropy H.
z Such techniques are called Entropy Coding techniques.
z The best optimal solution of attaining R to H was proposed by
David Huffman (1950) as a part of his term project in the
Information theory class at MIT.
z It is now known as Huffman coding technique.
z Huffman’s trick, in today’s jargon, was to “think outside the box.”
z He studied binary code tree to establish properties that an optimal
prefix-free code should have.
z These few properties led to a simple recursive procedure for
constructing an optimal code.
ECE G311 – Image Coding-II Slide 7 of 36
Entropy Coding (2)
z Example-1: To illustrate Huffman coding technique consider our
4×8, 256-level image from an earlier example.
21 21 21 95 169 243 243 243
21 21 21 95 169 243 243 243
21 21 21 95 169 243 243 243
21 21 21 95 169 243 243 243
with gray-level histogram

Gray-Level Count Probability


21 12 3/8
95 4 1/8
169 4 1/8
243 12 3/8

ECE G311 – Image Coding-II Slide 8 of 36


Entropy Coding (3)
z Example-1: (Continued)
Reduction: Arrange gray-levels in the decreasing order of their
probabilities
Gray-Level Probability Reduction-1 Reduction-2

21 3/8 3/8 5/8

243 3/8 3/8 3/8

95 1/8 1/4

169 1/8

ECE G311 – Image Coding-II Slide 9 of 36


Entropy Coding (4)
z Example-1: (Continued)
Assignment: Arrange gray-levels in the decreasing order of their
probabilities
Gray-Level Probability Reduction-1 Reduction-2

1 21 1 3/8 1 3/8 0 5/8

00 243 00 3/8 00 3/8 1 3/8

010 95 1/8 01 1/4

011 169 1/8


The average bit-rate for this assignment is
RHuff = 83 × 1 + 83 × 2 + 18 × 3 + 18 × 3 = 1.875 < H = 1.81 bits
symbol
ECE G311 – Image Coding-II Slide 10 of 36
Entropy Coding (5)
z Example-2: (from Gonzalez and Woods)

RHuff = 0.4 × 1 + 0.3 × 2 + 0.1 × 3 + 0.1 × 4 + 0.06 × 5 + 0.04 × 5


= 2.2 bits/sym
H = 2.14 bits/sym
ECE G311 – Image Coding-II Slide 11 of 36
Entropy Coding (6)
z MATLAB Implementation: IPT does not have any functions for
Huffman encoding. However G&W book toolbox provides several
functions for Huffman data and image encoding.
„ CODE = HUFFMAN(P) returns a Huffman code as binary strings
in cell array CODE for input symbol probability vector P. Each
word in CODE corresponds to a symbol whose probability is at
the corresponding index of P. Uses the following two
functions.
„ SC = REDUCE(P) create a Huffman source reduction tree in a
MATLAB cell structure by performing source symbol
reductions until there are only two reduced symbols remaining.
„ MAKECODE(SC,CODEWORD) scan the nodes of a Huffman source
reduction tree recursively to generate the indicated variable
length code words. >> p = [0.1875,0.5,0.125,0.1875];
>> c = huffman(p)
c = ‘011’ ‘1’ ‘010’ ’00’
ECE G311 – Image Coding-II Slide 12 of 36
Entropy Coding (7)
z MATLAB Implementation (continued): The following G&W
book toolbox function performs Huffman image encoding.
„ Y = MAT2HUFF(X) Huffman encodes matrix X using symbol
probabilities in unit-width histogram bins between X's
minimum and maximum values. The encoded data is returned
as a structure Y:
‹ Y.code The Huffman-encoded values of X, stored in a
uint16 vector. The other fields of Y contain additional
decoding info.
>> x = imread(‘Tracy.tif’);
>> y = mat2huff(x);
>> cr1 = imratio(x,y)
cr1 = 1.2191
>>
>> save CTracy y;
>> cr2 = imratio(‘tracy.tif’,...
,’CTracy.mat’); Difference due to MATLAB
cr2 = 1.2365 data-format overhead
ECE G311 – Image Coding-II Slide 13 of 36
Entropy Coding (8)
z MATLAB Implementation (continued):
The following G&W book toolbox function performs Huffman
image decoding.
„ X = HUFF2MAT(Y) decodes a Huffman encoded structure Y
with uint16 fields. The output X is of class double.
>> load CTracy;
>> xhat = huff2mat(y);
>> x = imread(‘Tracy.tif’);
>> rmse = compare(x,xhat)
rmse = 0

z Thus Huffman technique is a lossless coding technique which


achieves the bit-rate very close to the entropy.
z In fact, there is no other uniquely decodable assignment that
can achieve the bit-rate < RHuff.
ECE G311 – Image Coding-II Slide 14 of 36
Entropy Coding (9)
z Disadvantage:
„ For a large number of levels, this scheme is time consuming.
„ For example, if L = 256 (8-bit image) then we will need 254
source reductions and then 254 code-word assignments.
„ If the probability distribution changes, then we will have to
repeat this procedure.
z Therefore, in practice, we consider other variable-length coding
schemes that are suboptimal yet simple to implement.
z Truncated Huffman Coding:
„ In this approach, most probable L1 < L levels are Huffman
coded.
„ The remaining (L – L1) levels are coded using a prefix-code
followed by a suitable fixed-length code.
ECE G311 – Image Coding-II Slide 15 of 36
Entropy Coding (10)
z Modified Huffman Coding:
„ Here again the most probable L1 < L levels are Huffman coded.
„ Next, the level-index i in {xi, i = 0, 1, …, L – 1} is represented
as ⎧0 ≤ l ≤ L1 − 1
i = kL1 + l ⎨
⎩0 ≤ k ≤ ( L / L1 ) − 1
For example, L
Let L = 256, L1 = 8 ⇒ = 32 = 25
L1
then 0 ≤ l ≤ 7, 0 ≤ k ≤ 31
„ Now the remaining (L – L1) levels can be represented by the
indices k and l.
„ These remaining levels are coded by a prefix code for k and a
terminator code which is the Huffman code for l.
ECE G311 – Image Coding-II Slide 16 of 36
Entropy Coding (11)
z Group (BN) Codes:
„ When the gray-level probabilities obey a power law of the form
−β
p ( xi ) = α ( i + 1) ; i = 0,1,K , L − 1
for some positive β, then group codes are nearly optimal.
„ In this scheme, each code is constructed using two parts:
‹ Continuation bits, denoted by C, and
‹ Information bits that are fixed-length PCM codes.
„ In BN codes, N information bits are used for each continuation
bit.
„ The advantage of these group codes is the simplicity in design.
„ Many text images, when converted into run-lengths (to be
discussed later) follow the power-law distribution.
„ Hence group codes are used in Fax transmission.
ECE G311 – Image Coding-II Slide 17 of 36
Entropy Coding (12)
z Example-3: Consider an image with 6 levels.

Level Probability Huffman B1 B2


x0 0.4 1 C0 C00
x1 0.3 00 C1 C01
x2 0.11 011 C0C0 C10
x3 0.08 0101 C0C1 C11
x4 0.06 01000 C1C0 C00C00
x5 0.05 01001 C1C1 C01C00
H = 2.15 RHuff = 2.2 RB1 = 2.6 RB2 = 3.33

Code-words using B1:


x0 x2 x5 x1 → 00 10 10 0101 11 or 100000 11 1101
ECE G311 – Image Coding-II Slide 18 of 36
Entropy Coding (14)
z Example-4: (from Gonzalez and Woods)

ECE G311 – Image Coding-II Slide 19 of 36


Entropy Coding (16)
z Lempel-Ziv-Welch (LZW) Code:
This coding scheme has gained a wide acceptance especially for
computer files.
„ It is used in .zip, uuencode, uudecode, gzip, .tiff, etc.
algorithms.
„ The scheme uses variable-to-variable-length codes, in which
both the number of source symbols encoded and the number of
encoded bits per codeword are variable. Moreover, the code is
space-varying.
„ It does not require prior knowledge of the source statistics, yet
over time it adapts so that the average codeword length R per
source letter is minimized.
„ Such algorithms are called universal Algorithms.

ECE G311 – Image Coding-II Slide 20 of 36


Entropy Coding (16)
z Lempel-Ziv-Welch (LZW) Code: (continued)
„ Two schemes were developed in 1977-78.
„ The first, LZ77, uses string-matching on a sliding window;
whereas the second, LZ78, uses an adaptive dictionary.
„ Although newer schemes have improved upon them, LZW
scheme provides a simple approach to understanding universal
data compression algorithms.
„ Basic Idea:
‹ Parse the data as it comes from the source into variable-
length blocks called phrases.
‹ When a new sequence (old phrase + new symbol) is
observed, a new phrase is created.
‹ New phrase is encoded as the position of the old phrase
concatenated by the new symbol.
z This scheme is ill suited for hand calculations (needs software).
ECE G311 – Image Coding-II Slide 21 of 36
Entropy Coding (17)
z Example-5: Consider the 4×4, 8-bit
image shown on the right. (G&W) 39 39 126 126
„ A dictionary of 512 words is 39 39 126 126
created as shown below on the 39 39 126 126
right. 39 39 126 126
„ The first 256 entries are for basic
symbols and are considered as Initial 512-word Dictionary

initial conditions. Dictionary


Entry
Location
„ The remaining entries are initially 0 0
empty. 1 1
... ...
„ The image is processed left-to- 255 255
right and top-to-bottom. 256 −
... ...
„ The coding process is shown in the 511 −
table on the next slide.
ECE G311 – Image Coding-II Slide 22 of 36
Entropy Coding (18)
z Example-5: (continued)
Currently Dictionary
Recognized Pixel Being Encoded Location Dictionary
Sequence Processed Output (Codeword) Entry
39
39 39 39 256 39-39
39 126 39 257 39-126
126 126 126 258 126-126
126 39 126 259 126-39
39 39
39-39 126 256 260 39-39-126
126 126
126-126 39 258 261 126-126-39
39 39
39-39 126
39-39-126 126 260 262 39-39-126-126
126 39
126-39 39 259 263 126-39-39
39 126
39-126 126 257 264 39-126-126
126 126

Thus the original (16×8=) 128-bit image is coded with (10×9=)


90-bit image with the compression ratio of 1.42.
ECE G311 – Image Coding-II Slide 23 of 36
Entropy Coding (19)
z Example-6: (G&W)
Tracy.tif Tracy_LZW.tif

>> cr = imratio('Tracy.tif','Tracy_LZW.tif')
cr =
1.6729
which is a larger CR than the Huffman encoding because LZW
uses correlations between pixels which Huffman does not.
ECE G311 – Image Coding-II Slide 24 of 36
Predictive Coding
z This technique exploits interpixel redundancy to achieve a
significant amount of data compression.
z Let
x(n1, n2 ) : zero-mean random field
and
)
x ( n1 , n2 ) causal optimal predictor
= E ⎡⎣ x ( n1 , n2 ) past signal values x ( k1 , k2 ),(k1 , k2 ) < ( n1 , n2 ) ⎤⎦
Then )
e( n1 , n2 ) x ( n1 , n2 ) − x ( n1 , n2 )
is the prediction error (also known as the Innovations Process).
z It is a causal, causally invertible, and uncorrelated random field.

ECE G311 – Image Coding-II Slide 25 of 36


Predictive Coding (2)
z Basic Principle:
Remove the mutual redundancy between successive pixels by
quantizing and coding only the new information contained in the
innovations process or in the error difference image.
z In general, the optimal predictor (conditional mean) is a nonlinear
function of the past pixel values.
z However, in the case of a Gaussian random field, the optimal
estimator is also linear which is easier to implement.
z For ease of implementation, we will consider only linear (and
hence suboptimum) predictors.
z In this case, the prediction error is still causal, causally invertible,
but is not uncorrelated (or white).

ECE G311 – Image Coding-II Slide 26 of 36


Predictive Coding (3)
z Example-7:
Consider the following four predictors:
)
x1 ( n1 , n2 ) = 0.97 x ( n1 , n2 − 1)
)
x2 ( n1 , n2 ) = 0.5 x ( n1 , n2 − 1) + 0.5 x ( n1 − 1, n2 )
)
x3 ( n1 , n2 ) = 0.75 x ( n1 , n2 − 1) + 0.75 x ( n1 − 1, n2 ) − 0.5 x ( n1 − 1, n2 − 1)
) ⎧0.97 x ( n1 , n2 − 1) Δh ≤ Δv
x4 ( n1 , n2 ) = ⎨
⎩0.97 x ( n1 − 1, n2 ) otherwise
Δh = x ( n1 − 1, n2 ) − x ( n1 − 1, n2 − 1)
Δv = x ( n1 , n2 − 1) − x ( n1 − 1, n2 − 1)
The error images are:
ek = x(n1, n2 ) − xˆk (n1, n2 ); k = 1, 2,3, 4
ECE G311 – Image Coding-II Slide 27 of 36
Predictive Coding (4)
z Example-7: (continued)

e1 (n1, n2 ) e2 (n1, n2 )

e3 (n1, n2 ) e3 (n1, n2 )

The higher-order predictor gives the best result.


ECE G311 – Image Coding-II Slide 28 of 36
Predictive Coding (5)
z Optimum 2-D Linear Predictor: Using the image formation
model, the one-step linear predictor of x(n1, n2) is given by
)
x ( n1 , n2 ) ∑ ak1 ,k2 x(n1 − k1, n2 − k2 )
( k1 ,k2 )∈R a
where Ra is the model support for the NSHP {ak1,k2} coefficients.
„ These coefficients are determined by minimizing the MSE
)
E ⎡⎢ e( n1 , n2 ) ⎤⎥ E ⎡⎢ x ( n1 , n2 ) − x ( n1 , n2 ) ⎤⎥
2 2
⎣ ⎦ ⎣ ⎦
„ This minimization is done using the orthogonality principle
which results in the normal set of equations:
∑ al , l
1 2
Rx ( k1 − l1 , k2 − l 2 ) = Rx ( k1 , k2 )
or in matrix notation
Ra = r ⇒ a = R − 1r
ECE G311 – Image Coding-II Slide 29 of 36
Predictive Coding (6)
z Optimum 2-D Linear Predictor: (continued)
Ra = r ⇒ a = R − 1r
where
„ R is the autocorrelation matrix,
„ r is the autocorrelation vector, and
„ a is the vector of unknown coefficients.
z The prediction error is zero mean and its mean-squared value or
variance is given by
σ e2 = σ 2x − ∑ ak1 ,k2 Rx ( − k1 , − k2 )
( k1 ,k2 )

where σ 2x is the variance of the RF x ( n1 , n2 ).

ECE G311 – Image Coding-II Slide 30 of 36


Predictive Coding (7)
z Predictor Geometry:
Ra
( n1 , n2 )

z Encoder Structure:
TRANSFORMATION
x ( n1 , n2 ) + e( n1 , n2 ) CODEWORD Bit
QUANTIZER Stream
− ASSIGNMENT
PREDICTOR )
x ( n1 , n2 )

High-correlated, Uncorrelated,
Large-variance signal Small-variance signal

ECE G311 – Image Coding-II Slide 31 of 36


Predictive Coding (8)
z Linear Predictive Coding (LPC) Techniques:
Based on the complexity in the predictor and the quantizer, we
have three approaches:
„ Delta Modulation (DM):
Uses a 1st-order one-step predictor and one bit in the quantizer.
„ Differential Pulse Code Modulation (DPCM):
Uses higher-order predictors and more bits in the quantizer.
There are two possibilities:
‹ Line-by-Line DPCM:
This approach predicts one entire scan-line using a 1-D
vector predictor.
‹ 2-D DPCM:
This approach predicts one pixel at a time using 2-D scalar
predictor.
ECE G311 – Image Coding-II Slide 32 of 36
Predictive Coding (9)
1. Delta Modulation:
This is the simplest predictive coder which employs
„ One-step (first-order) predictor:
x ( n1 , n2 ) = ρh x ( n1 , n2 − 1) + e( n1 , n2 )
14)4244 3
x ( n1 ,n2 )
„ 1-bit Quantizer:
⎧ +Δ e( n1 , n2 ) > 0
e( n1 , n2 ) = ⎨ ; Δ : Step-size
⎩ −Δ e( n1 , n2 ) < 0
„ Encoder:
x ( n1 , n2 ) + e(n1 , n2 ) +Δ e% ( n1 , n2 ) = Δ sgn [ e( n1 , n2 )]
− x) (n , n ) −Δ
1 2
If e( n1 , n2 ) and Δ are small, then e% ( n1 , n2 ) ≈ e( n1 , n2 ).
Hence, x% ( n1 , n2 ) ρh x ( n1 , n2 − 1) + e% ( n1 , n2 ) ≈ x ( n1 , n2 ).
ECE G311 – Image Coding-II Slide 33 of 36
Predictive Coding (10)
1. Delta Modulation: (continued)
How should the predicted value be computed? Consider
x ( n1 , n2 ) + e(n1 , n2 ) +Δ
e% ( n1 , n2 ) = Δ sgn [ e( n1 , n2 )]
− x)%)(n1 , n2 ) −Δ
PREDICTOR FILTER
?
■ Decoder: Must generate pixel value from the quantized error.
)
e% ( n1 , n2 ) + x% ( n1 , n2 ) = x% ( n1 , n2 ) ≈ x ( n1 , n2 )

+ x% ( n1 , n2 ) ≈ x ( n1 , n2 )
e% ( n1 , n2 )
+
1 Pixel Delay
)
x% ( n1 , n2 ) ρh x% ( n1 , n2 − 1)
ECE G311 – Image Coding-II Slide 34 of 36
Predictive Coding (11)
1. Delta Modulation: (continued)
„ In the receiver, the decoder has to generate predictor
estimates based on x% ( n1 , n2 ), or equivalently, e% (n1 , n2 ).
„ Hence, it is necessary that the encoder also make use of e%
in order to maintain synchronization between the transmitter
and the receiver.
)
„ Therefore, we have to use e% ( n1 , n2 ) in order to generate x% , as
shown below:
) e% ( n1 , n2 )
x% ( n1 , n2 )
Filter
x% ( n1 , n2 − 1) +
x% ( n1 , n2 )
ρh 1 Pixel Delay
) +
x% ( n1 , n2 )

ECE G311 – Image Coding-II Slide 35 of 36


Predictive Coding (12)
1. Delta Modulation: (continued)
„ Encoder:

+ e( n1 , n2 ) +Δ e% ( n1 , n2 )
x ( n1 , n2 )
− −Δ

+
ρh 1 Pixel Delay
+
„ Decoder:

e% ( n1 , n2 ) + x% ( n1 , n2 )
+
1 Pixel Delay
ρh
ECE G311 – Image Coding-II Slide 36 of 36
Predictive Coding (13)
z Delta Modulation: (continued)
„ Disadvantages:
‹ Uses on the horizontal correlation but not higher-order or
2-D correlations.
‹ Slope overload.
‹ Granularity.
‹ Limited compression ratios (< 3).

Granularity

ECE G311 – Image Coding-II Slide 37 of 36


Predictive Coding (14)
1. Delta Modulation: (continued)
Example-8:

Original Image Delta Modulation: ρh = 0.97

ECE G311 – Image Coding-II Slide 38 of 36


Predictive Coding (15)
2. Line-by-Line DPCM
„ This technique treats each scan line as a 1-D signal and
performs an LPC on it.
„ It employs a higher-order 1-D predictor and more bits in the
quantizer.
„ Therefore, slope-overload and granularity problems are
avoided.
„ However true 2-D correlations are not used.
„ Encoder and Decoder Equations: Pth-order predictor
)
x% ( n1 , n2 ) = ∑ p =1 a p x% ( n1 , n2 − p )
P

)
e( n1 , n2 ) = x ( n1 , n2 ) − x% ( n1 , n2 ); e% ( n1 , n2 ) = Q [ e( n1 , n2 )]

x% ( n1 , n2 ) = ∑ p =1 a p x% ( n1 , n2 − p ) + e% ( n1 , n2 )
P

ECE G311 – Image Coding-II Slide 39 of 36


Predictive Coding (16)
2. Line-by-Line DPCM: (continued)
„ Analysis:
If e% ( n1 , n2 ) ≈ e( n1 , n2 ), then x% ( n1 , n2 ) ≈ x ( n1 , n2 )
If P = 1 then
a1 = ρh : Horizontal correlation coefficient.
Hence for this case it can be shown that
1 ⎛ 1 ⎞
RPCM − R1D-DPCM = log 2 ⎜ 2⎟
2 ⎝ 1 − ρ h⎠
For example, if ρh = 0.97, then
RPCM − R1D-DPCM = 2 bpp ⇒ CR = 8 6 = 1.33
or if ρh = 0.999, then
RPCM − R1D-DPCM = 4.5 bpp ⇒ CR = 2.28
ECE G311 – Image Coding-II Slide 40 of 36
Predictive Coding (17)
2. Line-by-Line DPCM: (continued)
„ Example-9

Original Image Line-by-Line DPCM:


ρh = 0.97, 4-bit Quantizer

ECE G311 – Image Coding-II Slide 41 of 36


Predictive Coding (18)
3. 2-D DPCM
„ This is the most general predictive technique and employs a
causal NSHP model in the predictor and hence 2-D
correlations are used.
„ Encoder and Decoder Equations: Similar to 1-D LPC
)
x% ( n1 , n2 ) = ∑ ak1 ,k2 x% (n1 − k1, n2 − k2 )
( k1 ,k2 )∈R a
)
e( n1 , n2 ) = x ( n1 , n2 ) − x% ( n1 , n2 );
e% ( n1 , n2 ) = Q [ e( n1 , n2 )]
x% ( n1 , n2 ) = ∑ ak1 ,k2 x% ( n1 − k1 , n2 − k2 ) + e% ( n1 , n2 )
( k1 ,k2 )∈R a

ECE G311 – Image Coding-II Slide 42 of 36


Predictive Coding (19)
3. 2-D DPCM: (continued)
„ The predictor coefficients are given by

Ra = r ⇒ a = R −1r
where
‹ R is the autocorrelation matrix,
‹ r is the autocorrelation vector, and
‹ a is the vector of unknown coefficients.
„ The prediction error is zero mean and its mean-squared value
or variance is given by
σ e2 = σ 2x − ∑ ak1 ,k2 Rx ( − k1 , − k2 )
( k1 ,k2 )

where σ 2x is the variance of the RF x ( n1 , n2 ).

ECE G311 – Image Coding-II Slide 43 of 36


Predictive Coding (20)
3. 2-D DPCM: (continued)
„ Example-10: Consider a zero-mean separable RF with
l2
Rx ( l1 , l 2 ) = σ 2x
l1
ρv ρh
Note that

Rx (1,1) = σ 2x ρv ρh =
( )(
σ 2x ρv σ 2x ρh ) = R (1,0) R (0,1)
x x
σ 2x Rx (0,0)
Then Ra = r yields
Rx (1,0) R (0,1) R (1,1)
a1,0 = = ρv ; a0,1 = x = ρh ; a1,0 = x = − ρ v ρh
Rx (1,0) Rx (1,0) Rx (1,0)
This gives a very simple prediction mask:
− ρ v ρh ρv
ρh ( n1 , n2 )
ECE G311 – Image Coding-II Slide 44 of 36
Predictive Coding (21)
3. 2-D DPCM:
„ Example-10: (continued)
Note that
E [ e( n1 , n2 )] = 0
E [ e( n1 , n2 )e( k1 , k2 )] = 0,( k1 , k2 ) ≠ ( n1 , n2 ) ⇒ Uncorrelated
σ e2 = σ 2x (1 − ρv2 )(1 − ρh2 )
‹ Thus this predictor requires only the horizontal and
vertical correlations which are easy to compute.
‹ If the image is highly correlated then ρh ≈ ρh ≈ 1 (but < 1).
Hence
(1 − ρh2 )(1 − ρv2 ) 1 ⇒ σ e2 σ 2x
Therefore, we are successful in converting a highly
correlated, high variance image into an uncorrelated, low
variance “difference” image.
ECE G311 – Image Coding-II Slide 45 of 36
Predictive Coding (22)
3. 2-D DPCM:
„ Example-10: (continued)
‹ The rate reduction is given by

1 ⎛ σ 2x ⎞
RPCM − R2D-DPCM = log 2 ⎜ 2 ⎟
2 ⎝ σe ⎠
1 ⎛ 1 ⎞
= log 2 ⎜ 2 2 ⎟
2 ⎝ (1 − ρv )(1 − ρh ) ⎠
For example, if ρh = ρv = 0.97, then
RPCM − R2D-DPCM = 4 bpp ⇒ CR = 8 / 4 = 2
If ρh = ρv = 0.997, then
RPCM − R2D-DPCM = 7.4 bpp ⇒ CR = 13
ECE G311 – Image Coding-II Slide 46 of 36
Predictive Coding (23)
3. 2-D DPCM: (continued)
„ Encoder:

+ e( n1 , n2 ) e% ( n1 , n2 )
x ( n1 , n2 ) QUANTIZER

+
NSHP Predictor
+
„ Decoder:

e% ( n1 , n2 ) + x% ( n1 , n2 )
+
NSHP Predictor

ECE G311 – Image Coding-II Slide 47 of 36


Predictive Coding (24)
3. 2-D DPCM: (continued)
Example-11

Original Image 2-D DPCM: 4 bpp

ECE G311 – Image Coding-II Slide 48 of 36


Predictive Coding (25)
3. 2-D DPCM (continued): Example-12
1-bit 1.125-bits 1-bit 1.125-bits

2-bits 2.125-bits 2-bits 2.125-bits

3-bits 3.125-bits 3-bits 3.125-bits

DPCM Result Images DPCM Error Images


ECE G311 – Image Coding-II Slide 49 of 36
Predictive Coding (26)
4. Lossless DPCM
To preserve the quality of images, one could perform DPCM
without a quantizer. The required encoder and decoder are:
„ Encoder:

x ( n1 , n2 ) + e( n1 , n2 ) CODEWORD Bit
ASSIGNMENT Stream
− )
x ( n1 , n2 )
NEAREST
PREDICTOR INTEGER

„ Decoder:
Bit Symbol e( n1 , n2 ) x ( n1 , n2 )
Stream decoder
)
x ( n1 , n2 )
PREDICTOR

ECE G311 – Image Coding-II Slide 50 of 36


Predictive Coding (27)
4. Lossless DPCM
MATLAB Implementation (G&W Book Toolbox)
„ Y = MAT2LPC(X,a);
Encodes matrix X using 1-D lossless predictive coding.
A linear prediction of X is made based on the
coefficients in a. If a is omitted, a = 1 (for previous
pixel coding) is assumed. The prediction error is then
computed and output as encoded matrix Y.
„ X = LPC2MAT(Y,a);
Decodes input matrix Y based on linear prediction
coefficients in a and the assumption of 1-D lossless
predictive coding. If a is omitted, filter a = 1 (for
previous pixel coding) is assumed.

ECE G311 – Image Coding-II Slide 51 of 36


Predictive Coding (28)
4. Lossless DPCM
Example-13: Consider the aligned matchstick image
encoded using the following predictor
)
x ( m, n ) = round [ x ( m, n − 1) ]
The resulting integer-valued error image is computed and
coded using the mat2lpc function.
>> x = imread(‘aligned_matches.tif’);
>> e = mat2lpc(x);
>> entropy(e)
ans = 5.9727 % Less than image entropy
% equal to 7.3505

ECE G311 – Image Coding-II Slide 52 of 36


Predictive Coding (29)
4. Lossless DPCM
Example-13: (continued)
>> imshow(mat2gray(e));
>> y = mat2huff(e);
>> cr = imratio(x,y);
cr = 1.3311 % more than 1.0821 for
% the original image

>> [h,f] = hist(e(:)*512,512);


>> bar(h,f,’k’);

>> xhat = lpc2mat(huff2mat(y));


>> compare(x,xhat)
ans = 0

ECE G311 – Image Coding-II Slide 53 of 36

Vous aimerez peut-être aussi