%
% Written by Alexander Stoytchev
%

levels=5;
G = cell(levels, 1);
L = cell(levels, 1);

%filter=[ 0.05, 0.25, 0.4, 0.25, 0.05];
filter=[-0.05, 0.25, 0.6, 0.25,-0.05];

% Read the image
G{1}= imread('lena_bw.gif');

figure; imshow(G{1})

%Construct the Gaussian Pyramid
for i=2:levels

  Rd  = Reduce(G{i-1}, filter);  % reduce the image
  Ri  = uint8(Rd);               % convert it to int
  G{i}=Ri;                       % store it in the pyramid structure 
  figure; imshow(G{i})
end


%Construct the Laplacian Pyramid

L{levels} = G{levels};  % the last element is always the same 

for i=1:levels-1

   Ed = Expand(G{i+1}, filter);  % expand the image in the Gaussian pyramid
   L{i} = double(G{i}) - Ed;     % store it in the pyramid structure
   figure; imshow(uint8(L{i}+128))
end

figure; imshow(L{levels})