The Wayback Machine - https://web.archive.org/web/20240811082952/https://www.geeksforgeeks.org/lossless-predictive-coding-in-matlab/
Open In App

Lossless Predictive Coding in MATLAB

Last Updated : 09 Nov, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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:

 



Previous Article
Next Article

Similar Reads

How to Select Random Rows from a Matrix in MATLAB?
A matrix is an n x n array that stores integers, floating point numbers or alphanumeric data in MATLAB. Indexing a matrix is the same as indexing an array. Syntax:matrix_name(i,j)where, i is the row number, and J is the column number which is to be indexed. Example 1: C/C++ Code % MATLAB code for select % random matrix elements mat = magic(5); mat(
2 min read
MATLAB Annotation
Annotations in MATLAB is a way of adding explanation or notes to the plots. Annotations add more information to the plots. There are different syntax formations for adding annotations to a plot: annotation(lineType,x,y)annotation(lineType)annotation(shapeType,dim)annotation(shapeType)annotation(___,Name,Value) Let's discuss all the above functions
3 min read
Global Variables in MATLAB
Variables in programming are generally storage spaces to store a certain type of data. There are many types of variables, but two commonly used types are local and Global variables. Generally, each MATLAB function has its own local variables. But sometimes for the sake of programming, we need to change the value of the local variable in another fun
4 min read
How to Calculate Harmonic Mean in MATLAB?
Harmonic mean is a type of mean, which is a measure of central tendencies of data, in statistics that gives large weightage to smaller data and small weightage to larger data. The Harmonic Mean in mathematical terms is nothing but the reciprocal of the mean of reciprocal values of all the data elements. Harmonic Mean in MATLAB:MATLAB provides a bui
2 min read
Copy Objects in MATLAB
In MATLAB, there are two kinds of objects - handles and values. The value objects are ordinary MATLAB objects which behave normally to copy operations. It means that when a value object is copied, the new copies of that object are completely independent of the original one i.e., if the original's value is changed, the copied object will not be chan
2 min read
How to create a function in MATLAB ?
A function is a block of statements that intend to perform a specific task. Functions allow the users to reuse the code frequently. MATLAB has several predefined functions which are ready to use such as sin(), fact(), cos() etc. MATLAB also allows the users to define their own functions. Syntax: function output_params = function_name(iput_params) %
2 min read
Creating Apps Using App Designer in MATLAB
MATLAB is a powerful, high-level programming language. Matlab is widely used for designing systems by engineers and scientists and we all know that the best way to represent any idea is by using a simple but effective GUI. Matlab app builder provides you the power to build different apps, to represent your idea in a GUI-friendly manner. In this art
3 min read
Mesh Surface Plot in MATLAB
Mesh Surface Plot is used to depict f(X, Y, Z) in a three-dimensional space. Matlab allows users to create mesh surface plots using the mesh() method. Different syntax of mesh() method are: Mesh(X, Y, Z)Mesh(Z)Mesh(___,C)Mesh(___, Name, Value)S = mesh()Mesh(ax,____)Mesh(X, Y, Z)It plots X, Y, Z on a three-dimensional surface.Matrices X, Y are plott
3 min read
How To Export a Matrix as a CSV File in MATLAB?
A CSV file - Comma Separated File, as the name suggests, is a file that stores data delimited by a ' , '. In MATLAB, there is a simple way of exporting a matrix to a csv file. The writematrix() function is used to write a matrix into any desired file type. The syntax is writematrix(<matrix_name>, "filename.extension"); This will create a new
2 min read
Laplacian of Gaussian Filter in MATLAB
The Laplacian filter is used to detect the edges in the images. But it has a disadvantage over the noisy images. It amplifies the noise in the image. Hence, first, we use a Gaussian filter on the noisy image to smoothen it and then subsequently use the Laplacian filter for edge detection. Dealing with a noisy image without a Gaussian Filter:Functio
4 min read
three90RightbarBannerImg