⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decode_spiht.m

📁 输入:为需要压缩图象的名称,该主程序仅能构处理256灰度图,读者可以自行改编为RGB处理;ratio为压缩比率;level为小波分解的级数 输出:是解压完毕的图象数据矩阵
💻 M
字号:
function A=decode_SPIHT(Linein,Linelength,Tin,ALR)
if nargin==0
    line1='10110011000010000001010100000';
    line2='11100000000000000001010';
    line3='1010111010110000101111101101000100010001010001110000101000100110';
    line4='11000011000010100101010000011011101011101110011010001000101010001010111010011101111011000110';
    line5='0111010100101110010101011101111100100101011011111011001001000100101110010100101100';
    Linein=strvcat(line1,line2,line3,line4,line5);
    Linelength=[29,23,64,92,82];
    Tin=32;
    ALR=8;
end
%*****************************************************************************
global LIP      %LIP list of insignificant pixels
global LIS      %LIS list of insignificant set
global LSP      %LSP list of insignificant pixels
global LSPflag  %the breakpoint of the LSP refinement   (作为LSP细化时的处理分界点)
global LIStype  %LIS have two type:D and L              (作为D型与L型的区分bit)
global X        %Mapping result                         (扫描时根据它的顺序)   
global Index    %保存索引 
global A
global Codei

%*******************************************************************************

A=zeros(ALR);
A=A(1:end);         %将A整形成1维向量(第二列接在第一列的后面)
Alength=length(A);  %A矢量长度
X=mapping(ALR);     %找出扫描顺序存在X矩阵中
                    %以下将扫描顺序索引置于NN中
X=X(1:end);         %对应于A作整形
[XX,Index]=sort(X); %XX是1:end的向量而Index则保存了索引:A(Index(i))则找到第i个被扫描的A阵的元素

                    %initial the LIP,LSP and LIS
                    %初始化LIP,LSP及LIS
LIP=[1 2 3 4];      %LIP初始化为H及其三个子女
LIS=[2 3 4];        %LIS一开始是三个D型根节点,即作为H的子女O
LIStype=[1 1 1];    %D为类型1,0为类型L
LSP=[];             %置空
T=Tin;

for i=1:length(Linelength)
    LSPflag=length(LSP); 
    Codein=Linein(i,1:Linelength(i));
    Codei=1;
    
    DLIP(T,Codein)
    DLIS(T,Codein)
    DLSP(T,Codein)
    
    
    T=T/2;
    i=i+1;
    %P=reshape(A,8,8)
    
end
A=reshape(A,ALR,ALR);
%**************************************************************************



%--------------------------------------------------------------------------
%DLIP反LIP扫描,已经成功
function DLIP(T,Codein)
global A
global Codei    %由于DLIS应该在LIP之后的code位开始解码,所以把Codei放在全局
global Index
global LIP
global LIS
global LSP

LIPi=1;
while (LIPi<=length(LIP))  & (LIPi>0)   
    Aindex=Index(LIP(LIPi));
    if Codein(Codei)=='1'  
        Codei=Codei+1;
        if Codein(Codei)=='0'   
            A(Aindex)=1.5*T;
        else
            A(Aindex)=-1.5*T;
        end
        LSP=[LSP,LIP(LIPi)];
        LIP=[LIP(1:LIPi-1),LIP(LIPi+1:end)];
        LIPi=LIPi-1;
    end
    Codei=Codei+1;
    LIPi=LIPi+1;
end
%---------------------------------------------------


function DLIS(T,Codein)
global A
global Codei    %由于DLIS应该在LIP之后的code位开始解码,所以把Codei放在全局
global Index
global LIP
global LIS
global LIStype
global LSP

LISi=1;

while (LISi<=length(LIS))  & (LISi>0)   
    Ki=LIS(LISi);
    Oindex=MyChilds(Ki);
    if Codein(Codei)=='1'   
        Codei=Codei+1;
        if LIStype(LISi)==1 %若为D型集合,作如下处理
            for count=1:4
               Aindex=Index(Oindex(count));
               if Codein(Codei)=='1'   
                   Codei=Codei+1;
                   if Codein(Codei)=='0'  
                       A(Aindex)=1.5*T;
                   else
                       A(Aindex)=-1.5*T;
                   end
                   Codei=Codei+1;
                   LSP=[LSP,Oindex(count)];
               else
                   LIP=[LIP,Oindex(count)];
                   Codei=Codei+1;
               end
           end
           LIS=[LIS(1:LISi-1),LIS(LISi+1:end)];  %把D从LIS中提出
           LIStype=[LIStype(1:LISi-1),LIStype(LISi+1:end)];%同时移走标志
           LISi=LISi-1;
           
           if (DDCheck(Ki,A)==1) %该节点还有孙节点,置为类型L
                LIS=[LIS,Ki];
                LIStype=[LIStype,0];
           end
       else
           LIS=[LIS(1:LISi-1),LIS(LISi+1:end)];  %把D从LIS中提出
           LIStype=[LIStype(1:LISi-1),LIStype(LISi+1:end)];%同时移走标志
           LISi=LISi-1; 
           LIS=[LIS,Oindex(1),Oindex(2),Oindex(3),Oindex(4)];
           LIStype=[LIStype,1,1,1,1];%移入LIS,并标志为D
       end
   else
        Codei= Codei+1;   
   end
   LISi=LISi+1;
end
        
%细分LSP*********************************
function DLSP(T,Codein)
global A
global Codei    %由于DLIS应该在LIP之后的code位开始解码,所以把Codei放在全局
global Index
global LIP
global LIS
global LIStype
global LSP
global LSPflag

for LSPi=1:LSPflag
    Aindex=Index(LSP(LSPi));    
    if  Codein(Codei)=='1' 
        if (A(Aindex)>0)    %按符号不同作相应处理
           A(Aindex)=A(Aindex)+T/2;
        else
           A(Aindex)=A(Aindex)-T/2;
        end
    else
        if (A(Aindex)>0)
           A(Aindex)=A(Aindex)-T/2;
        else
           A(Aindex)=A(Aindex)+T/2;
        end
    end
    Codei=Codei+1;
 end
 
 
 
 %-----------------------------------------------------------
function O=MyChilds(i)
% 找儿子-----------------------
O= [4*i-3 : 4*i];
%---------------------------------------------------
function result=Dcheck(i,A,T,result)
%result初始化为0,其值表示A中有否大于T
global Index 
t=1;
while ChildCheck(t*i,A)==1
    for k= 4*t*i-(4*t-1) : 4*t*i
        if abs(A(Index(k))) >= T
            result=1;
            return
        end
    end
    t=t*4;

end
%-----------------------------------------------
function X = mapping(n)
%this function find the scan order of the matrix
%"Z" type
if n == 2

   X = [1 2; 3 4];

else

   B = mapping(n/2);

   X = [B B+(n/2)^2; B+(n/2)^2*2 B+(n/2)^2*3];

end
function Dcheck=DDCheck(i,A)
%是否有儿子——————————
Dcheck=0;
if (i~=1) & ( 16*i<=  length(A) )
    Dcheck=1;
end
function Ccheck=ChildCheck(i,A)
Ccheck=0;
if (i~=1) & (4*i<length(A))
    Ccheck=1;
end



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -