function rpyr = reconstruct(epyr, stoplevel, method, param1)
% reconstruct an image pyramid from an error pyramid
% takes a stop level to specify which error levels not to use
% takes a method string and its optional parameter

if(nargin <= 3)
   param1 = '';
end

[col, row, levels] = size(epyr);

rimage = getLevel(epyr, levels-1);
rpyr = addLevel(rimage);
for level = (levels-2):-1:0
   rimage = expandFunc(rimage, method, param1);
   if(level >= stoplevel)
      rimage = rimage + getLevel(epyr, level);
   end
   rpyr = addLevel(rimage, rpyr);
end


   