% Iterative smoother for 2D images
% 2009-Apr-21  CCK rewrote to use circshift instead of shift (the
%    latter is available only in Octave)
function result = smooth2(img, Niterations)

result = img;
for iteration = 1:Niterations
   result2 = zeros(size(img));
   for dim = [1, 2]
      for d = [-1,1]
         offset = [0,0];
         offset(dim) = d;
         result2 = result2 + circshift(result, offset);
      end
   end
   result = (result + result2/4)/2;
end
