process and MATLAB implementation of multi-level tree set splitting (SPIHT) algorithm (7) decoding process--scanning decoding

Source: Internet
Author: User
Tags comparison


Tip: The execution path for any sort algorithm is defined using the comparison result of the branch point. If the decoder and encoder use the same sorting algorithm, the decoder can obtain sort information by executing the same path for the factor comparison result of the encoder input.

So, simply change the "output" in the encoder mathematical expression to "input", the decoder can restore the data sorting information, while recovering the data sorting information, the decoder is also responsible for image reconstruction, for confirming the important factor of recovery, by sequencing scanning and fine scanning two steps to update the quantization value of the coefficients, Gradually improve the approximation accuracy and reconstruct the quality of the image.

Global RMat Cmat
% RMat, Cmat is the number of rows and columns of the mat, as global variables, used in the encoding, decoding of related programs

% read in the current LIS table length
Rlis=size (lis,1);
% ls is a pointer to the position of the current table key in the LIS, with an initial position of 1
Ls=1;
While Ls<=rlis
% read into the current LIS table entry type
Switch Lisflag (LS)
% ' D ' class table entry containing children and non-immediate descendants
Case ' D '
% read the coordinate value of the table entry
Rp=lis (ls,1);
Cp=lis (ls,2);
% depends on Sn to determine whether the table item ' D ' type descendants tree is important
If Sn (1) ==1
% each judgment is read into the first number of Sn, and immediately after judgment delete this digit
Sn (1) =[];
% Build child tree for this table item
Cho=coef_dol (RP,CP, ' O ');
% to judge the importance of each child separately
For R=1:4
% read in the child's coordinate value
Ro=cho (r,1);
Co=cho (r,2);
% judge the importance of the child
If Sn (1) ==1
Sn (1) =[];
% judge the sign of the child
If Sn (1) ==1
Sn (1) =[];
% generate the child's coefficient value
Decodemat (Ro,co) =1.5*2^n;
Else
Sn (1) =[];
Decodemat (Ro,co) =-1.5*2^n;
End
% Add the child to the important factor list LSP
Lsp=[lsp;cho (R,:)];
Else
% if not important, the child's coefficient value is 0
Decodemat (Ro,co) = 0;
Sn (1) =[];
% Add the child to the list of unimportant factors LIP
% the non-critical coefficients under this level of threshold may be important in the next level of decoding
Lip=[lip;cho (R,:)];
End
End
% generate non-direct descendant tree of the table entry
Chl=coef_dol (RP,CP, ' L ');
If ~isempty (ChL)
% if the ' L ' type tree is not empty, then add the table entry to the list of LIS's end waits for scanning
Lis=[lis; LIS (LS,:)];
% table item type changed to ' L ' type
Lisflag=[lisflag, ' L '];
At this point, the ' D ' type LIS scan of the table item ends, and the item and its type are deleted in the LIS
LIS (LS,:) =[];
Lisflag (LS) =[];
Else
% if the ' L ' type tree is an empty set
% the ' D ' type of the LIS scan of the table entry is ended, and the item and its type are deleted in the LIS
LIS (LS,:) =[];
Lisflag (LS) =[];
End
Else
% if the ' D ' descendant tree of the table item is not important, first remove the read-in Sn value
Sn (1) =[];
% then point the pointer to the next LIS table entry
ls=ls+1;
End
% update the current LIS's table length, go to the next table item scan
Rlis=size (lis,1);
Case ' L '
% on ' L ' class table items, no need to judge the importance of children
% read the coordinate value of the table entry
Rp=lis (ls,1);
Cp=lis (ls,2);
% determining whether the ' L ' descendant tree of the table item is important
If Sn (1) ==1
% If the descendant tree is important
Sn (1) =[];
% is the child tree that generated the table entry
Cho=coef_dol (RP,CP, ' O ');
% remove the ' L ' class table entry from the LIS
LIS (LS,:) =[];
Lisflag (LS) =[];
% add four children of a table entry to the end of the LIS, labeled ' D ' Class table entry
Lis=[lis;cho (1:4,:)];
Lisflag (end+1:end+4) = ' D ';
Else
% if the ' L ' type descendant tree of the table item is not important, first delete the read-in Sn value
Sn (1) =[];
% then point the pointer to the next LIS table entry
ls=ls+1;
End
% update the current LIS's table length, go to the next table item scan
Rlis=size (lis,1);
End
End
% to the LIS scan end, the threshold of this level of the index minus 1, ready to enter the next level of coding
n=n-1;


4. Fine Scan decoding Program

function Decodemat=decrefine (decodemat,rn,n,lsp_old)
The% function Decrefine () is a fine-decoding program that generates a list of important coefficients for the first-level decoding lsp_old, based on the input
% fine bit flow Rn improves the reconstruction accuracy of important coefficient values
% input parameters: decodemat--matrix of reconstructed coefficients after decoding by sort scan
% rn--fine-scan output bit stream
% n--Index of this level decoding threshold
% lsp_old--List of important factors generated at the top level of decoding
% OUTPUT Parameters: decodemat--The reconstruction matrix after improving the precision of the important coefficients

Rlsp=size (lsp_old,1);
If ~isempty (lsp_old)
For R=1:RLSP
Dmat=decodemat (Lsp_old (r,1), Lsp_old (r,2));
% first read the value of the important coefficients in the reconstructed matrix DMat
Rmat=abs (DMat) + ( -1) ^ (1+RN (1)) *2^ (N-1);
% of absolute value of dMat, if Rn = 1, then add 2^ (N-1), otherwise subtract 2^ (N-1), result deposit RMat
If dmat<=0
Rmat=-rmat;
End
% if DMat is negative, then RMat is also converted to negative
Rn (1) =[];
% elimination of the RN information read
Decodemat (Lsp_old (r,1), Lsp_old (r,2)) =rmat;
% will improve the accuracy of the important coefficient values returned in the refactoring matrix
End
End

Ok. SPIHT algorithm encoding, decoding program to this is basically done, the next article we will use these programs to do an example demonstration.


2. Lip Scan decoding Program

function [Decodemat,sn,lsp,lip]=lip_decode (Decodemat,sn,n,lsp,lip)
The% function Lip_decode () updates the list of LIP, LSP, and refactor coefficient matrices based on the sort bit stream Sn Decodemat
% input parameters: decodemat--reconstruction coefficient matrix generated on the first level of decoding
% sn--This level decode sort bit stream
% n--Index of this level decoding threshold
% lsp--List of important factors generated at the top level of decoding
% lip--the list of unimportant factors generated at the first level of decoding
% OUTPUT parameters: decodemat--the reconstructed coefficient matrix updated after this level of lip scan
% sn--the sort bit stream updated after the lip list is scanned
% lsp--List of important factors updated after scan of lip list
% lip--List of unimportant factors updated after this level of LIP scan

Rlip=size (lip,1);
% r is a pointer to the position of the LIP currently read in the table entry
R=1;
The% decoding path is basically the same as the encoding path, but decoding is based on the sorting bit stream Sn to determine whether the coefficients are important
While R<=rlip
% read the coordinate value of the current table entry
Rn=lip (r,1);
Cn=lip (r,2);
% determines whether the table item is important according to Sn
% according to the principle of SN generation, each judgment is read into the first number of SN, immediately after the judgment to delete this number
If Sn (1) ==1
% if sn (1) = 1, indicates that the current table item is important
Sn (1) =[];
% is deleted after reading the SN data, so that SN (2) into SN (1), into the next judgment
The Sn (1) At this time is the positive and negative sign bit
If Sn (1) ==1
% Sn (1) = 1, the corresponding coefficient is a positive number, and its value is 1.5 times times the current level decoding threshold value
Decodemat (RN,CN) =1.5*2^n;
Sn (1) =[];
Else
% Sn (1) = 0, the corresponding coefficient is negative
Decodemat (RN,CN) =-1.5*2^n;
Sn (1) =[];
End
% Add the table entry to the important factor list LSP
LSP=[LSP; LIP (R,:)];
% remove the table entry from the LIP
LIP (R,:) =[];
Else
% if not important, then the corresponding coefficient value is 0
Decodemat (RN,CN) = 0;
Sn (1) =[];
% point pointer to next table item
r=r+1;
End
% judge the current LIP's table length
Rlip=size (lip,1);
End

3. LIS Scanning and decoding program

function [Lsp,lip,lis,lisflag,decodemat,n]=lis_decode (Decodemat,n,sn,lsp,lip,lis,lisflag)
The% function Lis_decode () updates the list of lip, LSP, and refactor coefficient matrices based on the sort bit stream Sn Decodemat
% input parameters: decodemat--the reconstructed coefficient matrix updated after this level of LIP scan
% n--Index of this level decoding threshold
% sn--sorted bit stream after interception by this level of LIP scan
% lsp--List of important factors updated after a LIP scan of this level
% lip--List of unimportant factors updated after this level of LIP scan
% lis--List of unimportant subsets generated on the previous level of encoding
% lisflag--The list of non-critical subset table item types generated on the first level of encoding
% output parameters: lsp--A list of important factors that are updated after this level of LIS scanning
% lip--List of unimportant factors updated after processing of this level LIS scan
% lis--List of unimportant subsets updated after this level of LIS scan
% lisflag--List of non-critical subset table item types updated after this level of LIS scan
% decodemat--the reconstructed coefficient matrix after this level of LIS scan
% n--Index of the next level decoding threshold

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.