function W = HWV(n,k,i,j,t) % HWV1 two-dimensional Haar wavelet of type t % % HWV1(n,k,i,j) is a 2^n-by-2^n matrix with all zeros except % the 2^k x 2^k block W(i*2^k+1:(i+1)*2^k,j*2^k+1:(j+1)*2^k). % The entries of this block depend on the type t: % if type t = 1, then w=[ 1, 1; 1, 1] (default) % if type t = 2, then w=[ 1, 1;-1,-1] -- horizontal -- % if type t = 3, then w=[ 1,-1; 1,-1] -- vertical -- % if type t = 4, then w=[ 1,-1;-1, 1] -- diagonal -- % where in each case 1 stands for a ones(2^(k-1),2^(k-1)). % % Main use is in conjunction with fasthaar2 and fastinvhaar % to illustrate one approach to image compression / coding. % To plot the wavelet, use e.g. % colormap(gray) % n=6; k=2; % for i=0:2^(n-k)-1, for j=0:2^(n-k)-1 % image(32*(1+hwv(n,k,i,j,4))); pause(0.05), end, end % % Matt Kawski 8-8-2008 % http://math.asu.edu/~kawski % kawski@asu.edu % if nargin < 5; t=4; end if nargin < 1; n=4; k=2; i=2; j=3; t=4; end if k<1, disp('the second parameter must be positive integer'), end if k>n, disp('the second parameter must be smaller than the first'), end if i>2^(n-k)-1, disp('the third parameter i must be less than 2^(n-k)-1'), end if j>2^(n-k)-1, disp('the fourth parameter j must be less than 2^(n-k)-1'), end N=2^n; W=zeros(N,N); Z=ones(2^(k-1),2^(k-1));%% /2^(k-1); %% /2^(n-k+1); %% normalization??? a=1; if t>2, b=-1; else b=1; end if mod(t,2)>0, c=1; else c=-1; end if (t-1)*(4-t)>0, d=-1; else d=1; end W(i*2^k+1:(2*i+1)*2^(k-1),j*2^k+1:(2*j+1)*2^(k-1))=a*Z; W((2*i+1)*2^(k-1)+1:(i+1)*2^k,j*2^k+1:(2*j+1)*2^(k-1))=b*Z; W(i*2^k+1:(2*i+1)*2^(k-1),(2*j+1)*2^(k-1)+1:(j+1)*2^k)=c*Z; W((2*i+1)*2^(k-1)+1:(i+1)*2^k,(2*j+1)*2^(k-1)+1:(j+1)*2^k)=d*Z; % colormap(gray) % image(32*(1+W)) end