Open In App

Lossless Predictive Coding in MATLAB

Last Updated : 09 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In Lossless Predictive Coding A new pixel value is obtained by finding the difference between the predicted pixel value and the current pixel. In other words, this is The new information of a pixel is defined as the difference between the actual and predicted value of that pixel. 

 The approach commonly referred to as lossless predictive coding, is based on eliminating the interpixel redundancies of closely spaced pixels by extracting and coding only the new information in each pixel. 

 Lossless predictive coding is a type of lossless image comparison algorithm.
 

Lossless comparison is where images are being compressed but without the loss of data. Therefore lossless comparison algorithms for commonly used in such applications where reliability and preservation of data are very crucial however compression ratio is small in comparison to the lossy comparison.

Lossless Coding Model:

The predictor uses a pixel from the input image that is F(n) to estimate a pixel’s future value based on information from the past. Past inputs are historical facts. The predicted value, denoted by f(n) and [f cap], which is the anticipated value, is then rounded to the nearest integer.

The prediction error is codified using f(n) and f. (n)

e(n)=f(n)-f is the error code (n)

Note: It’s critical to inform the decoder of this issue.

The variable-length code generated by a symbol encoder is used to produce the following element.

Lossless Coding Model

 

The Predictor

Typically, a prediction is created by linearly combining m prior pixels.

\hat {f_n}= r o u n d [\sum_{i = 1 }^m\ a l p ha_ i f_{ n -i} ]

The round function is used to indicate the rounding to the closest integer operation, where m is the order of the linear predictor. The coefficients of prediction for 1, 2, and m are i.

Dimensions:

The m samples used in 1-D linear predictive coding come from the current scan line and are used to forecast the value of each pixel. In 2-D linear predictive coding, the current and previous scan lines’ m samples are used to predict each pixel’s value. In 3-D linear predictive coding, the current and previous images in a sequence of images are used as the m samples to forecast the value of each pixel.

\hat{f_n}(x,y)= round[\sum_{i=1}^m\alpha_if(x,y-i)]

The Decoder:

e(n) is reconstructed using the received variable code words, and the original input sequence is recreated using the inverse process. 

f(n)= e(n)+ f(n)

 

Example 1:

Matlab

% MATLAB code for Lossless Predictive Coding
C=[9,8,7,6; 1,2,3,4];
display(C);
b=C;
  
% prediction error
for i = 1:size(C,1)
    for j = 2:size(C,2)
        b(i,j)=b(i,j)-C(i,j-1);
    end
end
display(b);
  
% Huffman coding
A=reshape(b,[],1);
[D1,x]=hist(A,min(min(b)):max(max(b)));
sym=x(D1>0);
prob=D1(D1>0)/numel(b);
[dict,avglen] = huffmandict(sym,prob);
comp = huffmanenco(A,dict);
  
% Huffman Decoding
dsig = huffmandeco(comp,dict);
b=reshape(dsig,size(C,1),size(C,2));
d=b;
  
for i = 1:size(C,1)
    for j = 2:size(C,2)
        d(i,j)=d(i,j-1)+b(i,j);
    end
end
  
display(d);

                    

Output:

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads