您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 能源与动力工程 > 个人收集的一些关于小波分析的matlab程序
个人收集的一些关于小波分析的matlab程序都是从网上收集来的,在文档结构图里查看,每个标题对应一个程序,难免重复,请大家理解。标题:提升法97经典程序1.%%本程序实现任意偶数大小图像第二代双正交97提升小波变换%%注1:采用标准正交方法,对行列采用不同矩阵(和matlab里不同)2.%%注2:为了保证正交,所有边界处理,全部采用循环处理3.%%注3:正交性验证,将单位阵带入函数,输出仍是单位阵(matlab不具有此性质)4.%%注4:此程序是矩阵实现,所以图像水平分量和垂直分量估计被交换位置5.%%注5:此程序实现的是类小波(wavelet-like)变换,是介于小波包变换与小波变换之间的变换6.%%注6:此程序每层变换相对原图像矩阵,产生的矩阵都是正交阵,这和小波包一致7.%%注7:但小波变换每层产生的矩阵,是相对每个待分解子块的正交矩阵,而不是原图像的正交矩阵8.%%注8:且小波变换产生的正交矩阵维数,随分解层数2分减少9.%%注9:提升系数可以在MATLAB7.0以上版本,用liftwave('9.7')获取,这里直接给出,考虑兼容性10.%%注10:由于MATLAB数组下标从1开始,所以注意奇偶序列的变化11.%%注11:d为对偶上升,即预测;p为原上升,即更新%%编程人沙威安徽大学12.%%编程时间2004年12月18日%%x输入图像,y输出图像13.%%flag_trans为正变换或反变换标志,0执行正变换,1执行反变换14.%%flag_max,是否最大层数变换标志,0执行用户设定层数,1执行最大层数变换15.%%layer,用户层数设置(小于最大层)functiony=db97(x,flag_trans,flag_max,layer);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%16.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%17.18.%1.输入参数检查%矩阵维数判断19.[sa,sb]=size(x);if(sa~=sb)%防止非图像数据20.errordlg('非图像数据!');21.error('非图像数据!');22.end;%变换标志判断23.[sa,sb]=size(flag_trans);24.if((sa~=1)|(sb~=1))%变换标志错误25.errordlg('变换标志错误!');26.error('变换标志错误!');27.end;if((flag_trans~=1)&(flag_trans~=0))%变换标志错误28.errordlg('变换标志错误!');29.error('变换标志错误!');30.end;%最大层数标志判断31.[sa,sb]=size(flag_max);32.if((sa~=1)|(sb~=1))%最大层数标志错误33.errordlg('最大层数标志错误!');34.error('最大层数标志错误!');35.end;if((flag_max~=1)&(flag_max~=0))%最大层数标志错误36.errordlg('最大层数标志错误!');37.error('最大层数标志错误!');38.end;%用户设置层数判断39.if(flag_max~=1)[sa,sb]=size(layer);40.if((sa~=1)|(sb~=1))%层数设置错误41.errordlg('层数设置错误!');42.error('层数设置错误!');43.end;if(flag_max0)%层数设置错误44.errordlg('层数设置错误!');45.error('层数设置错误!');46.end;47.end;48.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%49.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%50.51.%2.提升系数确定52.%t1=liftwave('9.7');%获取提升系数(MATLAB7.0以后)d1=[-1.586100000000000e+000,-1.586134342069360e+000];53.p1=[1.079600000000000e+000,-5.298011857188560e-002];54.d2=[-8.829110755411875e-001,-8.829110755411875e-001];55.p2=[4.435068520511142e-001,1.576123746148364e+000];56.d3=-8.698644516247808e-001;57.p3=-1.149604398860242e+000;58.59.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%60.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%61.62.%3.分解层数确定63.%采用用户输入和自动给出最大层数两种方法N=length(x);%矩阵大小64.S=N;%变量65.s=log2(N);%最大循环次数66.n1=N/2;%初始一半矩阵大小67.n2=N;%初始矩阵大小68.u=0;%初始值%对非2的整数幂大小图像确定最大分解层数69.forss=1:s70.if(mod(S,2)==0)71.u=u+1;72.S=S/2;73.end;74.end;75.u=u-1;%分解最大层数减1(后面的边界处理造成)%最大层数确定76.if(flag_max==0)%手动输入77.T=layer;%用户输入值78.else%自动确定最大层数79.T=u;%分解最大层数80.end81.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%82.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%83.84.%4.最大层数和图像大小检查if(Tu)%防止用户层数越界85.errordlg('已超过最大分解层数!或者非偶数大小图像!');86.error('已超过最大分解层数!或者非偶数大小图像!');87.end;if(mod(N,2)~=0)%防止图像大小错误88.errordlg('非偶数大小图像!');89.error('非偶数大小图像!');90.end;91.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%92.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%93.94.%5.提升法正变换if(flag_trans==0)95.fortime=1:T;%行正变换96.97.%d;98.x1(n1,:)=x(n2,:)+d1(2)*x(n2-1,:)+d1(1)*x(1,:);99.x1([1:n1-1],:)=x([2:2:n2-2],:)+d1(2)*x([1:2:n2-3],:)+d1(1)*x([3:2:n2-1],:);100.101.%p;102.x(1,:)=x(1,:)+p1(2)*x1(n1,:)+p1(1)*x1(1,:);103.x([2:n1],:)=x([3:2:n2-1],:)+p1(2)*x1([1:n1-1],:)+p1(1)*x1([2:n1],:);104.x([n1+1:n2],:)=x1([1:n1],:);105.106.%d;107.x(n1+1,:)=x(n1+1,:)+d2(2)*x(n1,:)+d2(1)*x(1,:);108.x([n1+2:n2],:)=x([n1+2:n2],:)+d2(2)*x([1:n1-1],:)+d2(1)*x([2:n1],:);109.110.%p;111.x(n1,:)=x(n1,:)+p2(2)*x(n1+1,:)+p2(1)*x(n1+2,:);112.x(n1-1,:)=x(n1-1,:)+p2(2)*x(n2,:)+p2(1)*x(n1+1,:);113.x([1:n1-2],:)=x([1:n1-2],:)+p2(2)*x([n1+2:n2-1],:)+p2(1)*x([n1+3:n2],:);114.115.%归一116.x([1:n1],:)=p3*x([1:n1],:);117.x([n1+1:n2],:)=d3*x([n1+1:n2],:);clearx1;118.119.%列正变换120.121.%d;122.x1(:,[1:n1])=x(:,[2:2:n2]);123.124.%p;125.x(:,1)=x(:,1)-d1(1)*x1(:,n1)-d1(2)*x1(:,1);126.x(:,[2:n1])=x(:,[3:2:n2-1])-d1(1)*x1(:,[1:n1-1])-d1(2)*x1(:,[2:n1]);127.x(:,[n1+1:n2])=x1(:,[1:n1]);128.129.%d;130.x(:,n2)=x(:,n2)-p1(1)*x(:,n1)-p1(2)*x(:,1);131.x(:,[n1+1:n2-1])=x(:,[n1+1:n2-1])-p1(1)*x(:,[1:n1-1])-p1(2)*x(:,[2:n1]);132.133.%p;134.x(:,n1,:)=x(:,n1)-d2(1)*x(:,n2)-d2(2)*x(:,n1+1);135.x(:,[1:n1-1])=x(:,[1:n1-1])-d2(1)*x(:,[n1+1:n2-1])-d2(2)*x(:,[n1+2:n2]);136.137.%d;138.x(:,n1+1)=x(:,n1+1)-p2(1)*x(:,n1-1)-p2(2)*x(:,n1);139.x(:,n1+2)=x(:,n1+2)-p2(1)*x(:,n1)-p2(2)*x(:,1);140.x(:,[n1+3:n2])=x(:,[n1+3:n2])-p2(1)*x(:,[1:n1-2])-p2(2)*x(:,[2:n1-1]);141.142.%归一143.x(:,[1:n1])=d3*x(:,[1:n1]);144.x(:,[n1+1:n2])=p3*x(:,[n1+1:n2]);clearx1;145.146.n2=n2/2;%原大小147.n1=n2/2;%一半大小148.end;149.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%150.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%151.152.%6.提升法反变换else153.n2=N/(2.^(T-1));%分解最小子块维数154.n1=n2/2;155.fortime=1:T;%行反变换156.157.%去归一158.x([1:n1],:)=x([1:n1],:)/p3;159.x([n1+1:n2],:)=x([n1+1:n2],:)/d3;%反p;160.x(n1,:)=x(n1,:)-p2(2)*x(n1+1,:)-p2(1)*x(n1+2,:);161.x(n1-1,:)=x(n1-1,:)-p2(2)*x(n2,:)-p2(1)*x(n1+1,:);162.x([1:n1-2],:)=x([1:n1-2],:)-p2(2)*x([n1+2:n2-1],:)-p2(1)*x([n1+3:n2],:);163.164.%反d;165.x(n1+1,:)=x(n1+1,:)-d2(2)*x(n1,:)-d2(1)*x(1,:);166.x([n1+2:n2],:)=x([n1+2:n2],:)-d2(2)*x([1:n1-1],:)-d2(1)*x([
本文标题:个人收集的一些关于小波分析的matlab程序
链接地址:https://www.777doc.com/doc-4469000 .html