2代小波示意程式

superdont發表於2007-07-01
from:http://waveletlegend.spaces.live.com/

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  此程式用提升法實現第二代小波變換
%%  我用的是非整數階小波變換
%%  採用時域實現,步驟先列後行
%%  正變換:分裂,預測,更新;
%%  反變換:更新,預測,合併
%%  只做一層(可以多層,而且每層的預測和更新方程不同)
clear;clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%  1.調原始影象矩陣
load wbarb;  
%  下載影象
f
=X;         %  原始影象
% f=[0 0 0 0 0 0 0 0 ;...
%    0 0 0 1 1 0 0 0 ;...
%    0 0 2 4 4 2 0 0 ;...
%    0 1 4 8 8 4 1 0 ;...
%    0 1 4 8 8 4 1 0 ;...
%    0 0 2 4 4 2 0 0 ;...
%    0 0 0 1 1 0 0 0 ;...
%    0 0 0 0 0 0 0 0 ;];  %  原始影象矩陣
N
=length(f);         %  影象維數
T
=N/2;               %  子影象維數
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%正變換%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%   1.列變換
%  A.分裂(奇偶分開)
f1
=f([1:2:N-1],:);  %  奇數
f2
=f([2:2:N],:);    %  偶數
% f1(:,T+1)=f1(:,1);  %  補列
% f2(T+1,:)=f2(1,:);  %  補行
%  B.預測
for i_hc=1:T;
    high_frequency_column(i_hc,:)
=f1(i_hc,:)-f2(i_hc,:);
end;
% high_frequency_column(T+1,:)=high_frequency_column(1,:);  %  補行
%  C.更新
for i_lc=1:T;
    low_frequency_column(i_lc,:)
=f2(i_lc,:)+1/2*high_frequency_column(i_lc,:);
end;
%  D.合併
f_column([
1:1:T],:)=low_frequency_column([1:T],:);
f_column([T
+1:1:N],:)=high_frequency_column([1:T],:);
   
   
figure(
1)
colormap(map);
image(f);
figure(
2)
colormap(map);
image(f_column);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%   2.行變換
%  A.分裂(奇偶分開)
f1
=f_column(:,[1:2:N-1]);  %  奇數
f2
=f_column(:,[2:2:N]);    %  偶數

% f2(:,T+1)=f2(:,1);    %  補行
%  B.預測
for i_hr=1:T;
    high_frequency_row(:,i_hr)
=f1(:,i_hr)-f2(:,i_hr);
end;
% high_frequency_row(:,T+1)=high_frequency_row(:,1);  %  補行
%  C.更新
for i_lr=1:T;
    low_frequency_row(:,i_lr)
=f2(:,i_lr)+1/2*high_frequency_row(:,i_lr);
end;
%  D.合併
f_row(:,[
1:1:T])=low_frequency_row(:,[1:T]);
f_row(:,[T
+1:1:N])=high_frequency_row(:,[1:T]);
   
figure(
3)
colormap(map);
image(f_row);
 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%反變換%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%   1.行變換
%   A.提取(低頻高頻分開)
f1
=f_row(:,[T+1:1:N]);  %  奇數
f2
=f_row(:,[1:1:T]);    %  偶數

% f2(:,T+1)=f2(:,1);    %  補行
%  B.更新
for i_lr=1:T;
    low_frequency_row(:,i_lr)
=f2(:,i_lr)-1/2*f1(:,i_lr);
end;
%  C.預測
for i_hr=1:T;
    high_frequency_row(:,i_hr)
=f1(:,i_hr)+low_frequency_row(:,i_hr);
end;
% high_frequency_row(:,T+1)=high_frequency_row(:,1);  %  補行

%  D.合併(奇偶分開合併)
f_row(:,[
2:2:N])=low_frequency_row(:,[1:T]);
f_row(:,[
1:2:N-1])=high_frequency_row(:,[1:T]);
   
figure(
4)
colormap(map);
image(f_row);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%   2.列變換
%  A.提取(低頻高頻分開)
f1
=f_row([T+1:1:N],:);  %  奇數
f2
=f_row([1:1:T],:);    %  偶數
% f1(:,T+1)=f1(:,1);  %  補列
% f2(T+1,:)=f2(1,:);  %  補行
%  B.更新
for i_lc=1:T;
    low_frequency_column(i_lc,:)
=f2(i_lc,:)-1/2*f1(i_lc,:);
end;
%  C.預測
for i_hc=1:T;
    high_frequency_column(i_hc,:)
=f1(i_hc,:)+low_frequency_column(i_hc,:);
end;
% high_frequency_column(T+1,:)=high_frequency_column(1,:);  %  補行
 
%  D.合併(奇偶分開合併)
f_column([
2:2:N],:)=low_frequency_column([1:T],:);
f_column([
1:2:N-1],:)=high_frequency_column([1:T],:);
   
   
figure(
5)
colormap(map);
image(f_column);
 

相關文章