function O = denoise_arf(image, model)
% denoises the image using the given model
% works only with grayscale images
  delta=400/model.niter;
  O = image;  
  g = zeros(size(O));
  nfilters = size(model.J, 2);
  for i = 1:model.niter    
      g      = zeros(size(O));  
      for j = 1:nfilters
        % Filter mask and mirrored filter mask
        f  = reshape(model.J(end:-1:1, j), model.dims)';
        fm = reshape(model.J(:, j), model.dims)';
        tmp = conv2(O, f, 'same');
        tmp2 = conv2(model.alpha(j) * tmp ./ (1 + 0.5 * tmp.^2), fm, 'same');
        g = g - tmp2;
      end
      O = O + delta * g ;
  end

