Code covered by the BSD License

# Multiresolution Gabor-like transforms

### Kunal Chaudhury (view profile)

11 May 2012 (Updated )

Matlab implementation of the multiresolution Gabor filters in 1 and 2 dimensions.

synthesis(lowpass, w, J, alpha, tau, L1, L2, L3, L4)
```function  reconImg  =  synthesis(lowpass, w, J, alpha, tau, L1, L2, L3, L4)
%
% reconstructs the image from the lowpass signals, and the complex wavelet
% coefficients.
% L1, ..., L4 are the end smaples required to invert the prefiltering.
%
M = length( lowpass(:,:,1) );
L = M * 2^J;
shift = 1/2;

[HH1, GG1] = filters(L, alpha,tau, 1);
[HH2, GG2] = filters(L, alpha, tau+shift, 1);

% orthogonal transformation (from 6 complex subbands to 12 real subbands)
YhR=cell(J,1);
for depth = 1 : J

YhR{depth}(:,:,1)  =  real(w{depth}(:,:,1));
YhR{depth}(:,:,2)  =  real(w{depth}(:,:,3));
YhR{depth}(:,:,3)  =  (real(w{depth}(:,:,5)) + ...
real(w{depth}(:,:,6))) / sqrt(2);
YhR{depth}(:,:,4)  =  imag(w{depth}(:,:,2));
YhR{depth}(:,:,5)  =  imag(w{depth}(:,:,4));
YhR{depth}(:,:,6)  =  (real(w{depth}(:,:,6)) - ...
real(w{depth}(:,:,5))) / sqrt(2);
YhR{depth}(:,:,7)  =  real(w{depth}(:,:,2));
YhR{depth}(:,:,8)  =  imag(w{depth}(:,:,3));
YhR{depth}(:,:,9)  =  (imag(w{depth}(:,:,5)) + ...
imag(w{depth}(:,:,6))) / sqrt(2);
YhR{depth}(:,:,10) =  imag(w{depth}(:,:,1));
YhR{depth}(:,:,11) =  real(w{depth}(:,:,4));
YhR{depth}(:,:,12) =  (imag(w{depth}(:,:,5)) - ...
imag(w{depth}(:,:,6))) / sqrt(2);
end

% lowpass for each channel
Yl_A = lowpass(:,:,1);
Yl_B = lowpass(:,:,2);
Yl_C = lowpass(:,:,3);
Yl_D = lowpass(:,:,4);

for depth = J : -1 : 1

G0 = HH1(1 : 2^(depth-1) : length(HH1));
G1 = GG1(1 : 2^(depth-1) : length(GG1));
H0 = HH2(1 : 2^(depth-1) : length(HH2));
H1 = GG2(1 : 2^(depth-1) : length(GG2));

% channel 1
R_A = [Yl_A    YhR{depth}(:,:,1);  YhR{depth}(:,:,2)  YhR{depth}(:,:,3)];

for i = 1 : 2*M
Y = fft(reshape(R_A(1:M,i),1,M),M);
v = reshape(R_A((M+1) : 2*M,i),1,M);
V = fft(v,M);
Y0 = G0(1:M).*Y + G1(1:M).*V;
Y1 = G0(M + (1:M)).*Y + G1(M+(1:M)).*V;
Y  =[Y0  Y1];
R_A(:,i) = reshape(ifft(Y,2*M),2*M,1);
end

for i = 1 : 2*M
Y = fft(R_A(i,1:M),M);
v = R_A(i,(M+1):2*M);
V = fft(v,M);
Y0 = G0(1:M).*Y+G1(1:M).*V;
Y1 = G0(M+(1:M)).*Y+G1(M+(1:M)).*V;
Y  = [Y0 Y1];
R_A(i,:) = ifft(Y,2*M);
end

% channel 2
R_B = [Yl_B   YhR{depth}(:,:,4); YhR{depth}(:,:,5)   YhR{depth}(:,:,6)];

for i = 1 : 2*M
Y  = fft(reshape(R_B(1:M,i),1,M),M);
v  = reshape(R_B((M+1):2*M,i),1,M);
V  = fft(v,M);
Y0 = H0(1:M).*Y + H1(1:M).*V;
Y1 = H0(M + (1:M)).*Y + H1(M + (1:M)).*V;
Y  = [Y0  Y1];
R_B(:,i) = reshape(ifft(Y,2*M),2*M,1);
end

for i = 1 : 2*M
Y  = fft(R_B(i,1:M),M);
v  = R_B(i,(M + 1):2*M);
V  = fft(v,M);
Y0 = H0(1:M).*Y + H1(1:M).*V;
Y1 = H0(M + (1:M)).*Y + H1(M + (1:M)).*V;
Y  = [Y0  Y1];
R_B(i,:) = ifft(Y,2*M);
end

% channel 3
R_C = [Yl_C   YhR{depth}(:,:,7); YhR{depth}(:,:,8)   YhR{depth}(:,:,9)];

for i = 1 : 2*M
Y  = fft(reshape(R_C(1:M,i),1,M),M);
v  = reshape(R_C((M + 1):2*M,i),1,M);
V  = fft(v,M);
Y0 = H0(1:M).*Y + H1(1:M).*V;
Y1 = H0(M + (1:M)).*Y + H1(M + (1:M)).*V;
Y  = [Y0  Y1];
R_C(:,i) = reshape(ifft(Y,2*M),2*M,1);
end

for i=1:2*M
Y  = fft(R_C(i,1:M),M);
v  = R_C(i,(M+1):2*M);
V  = fft(v,M);
Y0 = G0(1:M).*Y + G1(1:M).*V;
Y1 = G0(M + (1:M)).*Y + G1(M + (1:M)).*V;
Y  =[Y0 Y1];
R_C(i,:) = ifft(Y,2*M);
end

% channel 4
R_D = [Yl_D   YhR{depth}(:,:,10); YhR{depth}(:,:,11)  YhR{depth}(:,:,12)];

for i = 1 : 2*M
Y  = fft(reshape(R_D(1:M,i),1,M),M);
v  = reshape(R_D((M + 1):2*M,i),1,M);
V  = fft(v,M);
Y0 = G0(1:M).*Y + G1(1:M).*V;
Y1 = G0(M + (1:M)).*Y + G1(M + (1:M)).*V;
Y  = [Y0  Y1];
R_D(:,i) = reshape(ifft(Y,2*M),2*M,1);
end

for i = 1 : 2*M
Y  = fft(R_D(i,1:M),M);
v  = R_D(i,(M + 1):2*M);
V  = fft(v,M);
Y0 = H0(1:M).*Y + H1(1:M).*V;
Y1 = H0(M + (1:M)).*Y + H1(M + (1:M)).*V;
Y  = [Y0 Y1];
R_D(i,:)=ifft(Y,2*M);
end

Yl_A = R_A;
Yl_B = R_B;
Yl_C = R_C;
Yl_D = R_D;

M = 2*M;

end

reconImg = (1/4) * ( postfilter(Yl_A, L1, alpha, tau, 1) + ...
postfilter(Yl_B, L2, alpha, tau, 2) + ...
postfilter(Yl_C, L3, alpha, tau, 3) + ...
postfilter(Yl_D, L4, alpha, tau, 4));

```