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

📄 dbdec2.m

📁 用matlab编写的压缩解压缩程序
💻 M
字号:
function [a,b,c,d]=dbdec2(x,N)
%dbdec2  2-D Daubchies decompose 
%[a b c d]=dbdec2(x,N)

rhcoef=dbaux(N);
sx=size(x);
%extention matrix size
ex=ex_mat(x,N);

%calculate the db coef 
[hcoef,gcoef]=rh2g(rhcoef);
lhcoef=length(hcoef);

%db transform
lex=size(ex);
lrout=sx(1)+2*(N-1);
lcout=sx(2)+2*(N-1);
if sx(1)==1  
    %1-D
    cah=conv2(ex,hcoef)*sqrt(2);
    a=cah(1,lhcoef:2:lhcoef+lcout-1);
    cbh=conv2(ex,gcoef)*sqrt(2);
    b=cbh(1,lhcoef:2:lhcoef+lcout-1);
else 
    %2-D
    cah=conv2(ex,hcoef)*sqrt(2);
    ca=(conv2(cah',hcoef))'*sqrt(2);
    a=ca(lhcoef:2:lhcoef+lrout-1,lhcoef:2:lhcoef+lcout-1);
    cbh=conv2(ex,gcoef)*sqrt(2);
    cb=(conv2(cah',gcoef))'*sqrt(2);
    b=cb(lhcoef:2:lhcoef+lrout-1,lhcoef:2:lhcoef+lcout-1);
    cc=(conv2(cbh',hcoef))'*sqrt(2);
    c=cc(lhcoef:2:lhcoef+lrout-1,lhcoef:2:lhcoef+lcout-1);
    cd=(conv2(cbh',gcoef))'*sqrt(2);
    d=cd(lhcoef:2:lhcoef+lrout-1,lhcoef:2:lhcoef+lcout-1);
end

%-----------------------------------------------------%
% Internal Function(s)
%-----------------------------------------------------%
function a=ex_mat(c,N)
sx=size(c);
lf=2*(N-1);
dlf=2*lf;
if N>1
    if sx(1)==1
        a=exh(c,N);
        if mod(sx(2),2)
            a(sx(2)+dlf+1)=a(sx(2));
        end
    else
        for i=1:sx(1)
            tempa(i,:)=exh(c(i,:),N);
        end
        for j=1:sx(2)+dlf
            a(:,j)=(exh(tempa(:,j)',N))';
        end
        if mod(sx(1),2)
           a(sx(1)+dlf+1,:)=a(sx(1),:);
        end
        if mod(sx(2),2)
            a(:,sx(2)+dlf+1)=a(:,sx(2));
        end
    end
else
    a=c;
    if sx(1)==1
        if mod(sx(2),2)
            a(sx(2)+1)=a(sx(2));
        end
    else
        if mod(sx(1),2)
            a(sx(1)+1,:)=a(sx(1),:);
        end
        if mod(sx(2),2)
            a(:,sx(2)+1)=a(:,sx(2));
        end
    end
end
%-----------------------------------------------------%
% Internal Function(s)
%-----------------------------------------------------%
function a=exh(c,N)
sx=size(c);
lf=2*(N-1);
dlf=2*lf;
a(lf+1:lf+sx(2))=c;
if lf<=sx(2)
    a(lf+1:lf+sx(2))=c;
    a(lf:-1:1)=c(1:lf);
    a(sx(2)+lf+1:sx(2)+dlf)=c(sx(2):-1:sx(2)-lf+1); 
else
    llf=lf;
    rlf=lf;
    for i=1:round(lf/sx(2)-0.5)
        llf1=lf-i*sx(2);
        rlf1=lf+i*sx(2);
        a(llf:-1:llf1+1)=a(rlf+1:rlf1);
        rlf2=lf+2*sx(2)-i*sx(2);
        a(rlf1+1:rlf1+sx(2))=a(rlf2:-1:rlf2-sx(2)+1);   
        llf=llf1;
        rlf=rlf1;
    end
    re=mod(lf,sx(2));
    if re
        a(1:re)=a(rlf+re:-1:rlf+1);
        a(dlf+sx(2)-re+1:dlf+sx(2))=a(rlf2-i*sx(2):-1:rlf2-i*sx(2)-re+1);                 
    end               
end
%-----------------------------------------------------%
% Internal Function(s)
%-----------------------------------------------------%
function [h,g]=rh2g(rh)
%rh2g   Calculate the db coef 

for i=1:length(rh)
    g(i)=(-1)^i*rh(i);
end

h=rh(length(rh):-1:1);

⌨️ 快捷键说明

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