function red = reduceFunc(image, method, param1)

% generic reduce function, including filtering and decimating

if (strcmp(method,'burt'))
   W = param1;
   fimage = replicateConv(image, W);
%   imshow(fimage);
   red = decimate(fimage);
end

if (strcmp(method,'haar'))
   red = decimate(image);
end

if (strcmp(method,'ideal'))
   fft = fft2(image);
   [row, col] = size(image);
   
   xx = (-row/2+1):row/2;
   yy = (-col/2+1):col/2;
   [x, y] = meshgrid(xx,yy);
%   mask = [and(abs(x)<row/4, abs(y)<row/4)];
   mask = [(x.^2+y.^2) < row^2/16];
   mask = swapBlocks(mask);
   fft = fft.*mask;
%   figure(1);
%   imshow(swapBlocks(fft)/500);
   
   fimage = ifft2(fft);
%   figure(2);
%   imshow(fimage);
   red = decimate(fimage);
end

if (strcmp(method,'MMF'))
   N = param1;
   mimage = MMF(image, N);
   red = decimate(mimage);
end

if (strcmp(method, 'opt_lin'))
  order = param1; %size of the filter
  W = linear_kernel(order);
  red = replicateConv(image,W);
  red = decimate(red);
  red = round(red);
end

if (strcmp(method, 'opt_cub'))
  order = param1; %size of the filter
  W = cubic_kernel(order);
  red = replicateConv(image,W);
  red = decimate(red);
  red = round(red);
end

if (strcmp(method, 'spline'))
   order = param1;
   f1 = BsplineFilter(order);
   f2 = BsplineFilter(2*order+1);
   invf1 = invertFilter(f1, 512);
   invf2 = invertFilter(f2, 512);
   u = binomialFilter(order);
   
   BSimage = replicateConv(image, invf1'*invf1);
   DUALimage = replicateConv(BSimage, f2'*f2);
   DUALimage = 1/4*replicateConv(DUALimage, u'*u);
   DUALred = decimate(DUALimage);
   BSred = replicateConv(DUALred, invf2'*invf2);
   red = replicateConv(BSred, f1'*f1);
end
   

if (strcmp(method, 'opt_NL'))
   %   F = fspecial('gaussian', 5, 1);
   F = cubic_kernel(15);
   fimage = replicateConv(image, F);
   red = decimate(fimage);
end

if (strcmp(method, 'multi'))
   %   F = fspecial('gaussian', 5, 1);
   F = cubic_kernel(15);
   fimage = replicateConv(image, F);
   red = decimate(fimage);
end

