i'm trying to implement the haar wavelet transform of a 128×128 lena image by multiplying it by the transform matrix H as below:
x=imread('lena.jpg');
x=imresize(x,[128 128]);
X=x(:,:,1);
H=generate_haar(128);
X=cast(X,'double');
transformed=H*(X*H');
figure;imagesc(transformed);colormap gray;
function [Hr]=generate_haar(N)
N : size of matrix to be generated, N must be some power of 2.
p=[0 0];
q=[0 1];
n=nextpow2(N);
for i=1:n-1
p=[p i*ones(1,2^i)];
t=1:(2^i);
q=[q t];
end
Hr=zeros(N,N);
Hr(1,:)=1;
for i=2:N;
P=p(1,i); Q=q(1,i);
for j= (N*(Q-1)/(2^P)):(N*((Q-0.5)/(2^P))-1)
Hr(i,j+1)=2^(P/2);
end
for j= (N*((Q-0.5)/(2^P))):(N*(Q/(2^P))-1)
Hr(i,j+1)=-(2^(P/2));
end
end
Hr=Hr*(1/sqrt(N));
end
what i get is an almost black picture like this: what my code produces
and is not what i expect which must be a 1-level dwt of lena like this: 1-level Dwt of lena
i do not want to use the matlab functions dwt2 or wavedec2 .