N=512;row=512;  col=512;
fin_D04=fopen('D04.raw','r');
I_D04 = fread(fin_D04, [col row],'uint8=>uint8'); 
I_D04 = reshape(I_D04,row,col);
Y=I_D04;X=I_D04;
[A, D]=haart(X,1);
T=zeros(N,N);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
[A, D]=haart(T,1);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
Y(1:N,1:N)=T(1:N,1:N);
N=N/2;
X2=Y(1:N,1:N);
[A, D]=haart(X2,1);
T=zeros(N,N);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
[A, D]=haart(T,1);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
Y(1:N,1:N)=T(1:N,1:N);
N=N/2;
X3=Y(1:N,1:N);
[A, D]=haart(X3,1);
T=zeros(N,N);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
[A, D]=haart(T,1);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
Y(1:N,1:N)=T(1:N,1:N);
subplot(1,2,1)
imshow(Y);

N=512;row=512;  col=512;
fin_D23=fopen('D23.raw','r');
I_D23 = fread(fin_D23, [col row],'uint8=>uint8'); 
I_D23 = reshape(I_D23,row,col);
Y=I_D23;X=I_D23;
[A, D]=haart(X,1);
T=zeros(N,N);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
[A, D]=haart(T,1);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
Y(1:N,1:N)=T(1:N,1:N);
N=N/2;
X2=Y(1:N,1:N);
[A, D]=haart(X2,1);
T=zeros(N,N);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
[A, D]=haart(T,1);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
Y(1:N,1:N)=T(1:N,1:N);
N=N/2;
X3=Y(1:N,1:N);
[A, D]=haart(X3,1);
T=zeros(N,N);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
[A, D]=haart(T,1);
T(1:N,1:N/2)=A'; T(1:N,N/2+1:N)=D';
Y(1:N,1:N)=T(1:N,1:N);
subplot(1,2,2)
imshow(Y);