function Ac = fftcrop2(A, D1,D2)
% FFTCROP2 Perform post-FFT cropping
%
%    Ac = FFTCROP2(A, D1,D2) where A is the image and D1, D2 are
%    the dimensions of the original image and kernel, respectively.
%
%    See also FFTEXTEND2, FFTCONV2.

% Jerod Weinman
% jerod@acm.org
% 18 Mar (c) 2004
  
% $Id: fftcrop2.m 1 2009-05-07 13:41:00Z weinman $
 
% Jerod Weinman
% jerod@acm.org
% Copyright 2007, 2008, 2011
 
%    This file is part of Matlab SDMaxEnt.
%
%    Matlab SDMaxEnt is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    Matlab SDMaxEnt is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with Matlab SDMaxEnt.  If not, see <http://www.gnu.org/licenses/>.
  
  if nargin<3
    D2 = D1;
  end;
  
  ma = D1(1);
  na = D1(2);
  
  mb = D2(1);
  nb = D2(2);
  
  mc = ceil(mb/2);
  nc = ceil(nb/2);

  Ac = A(mc+(1:ma),nc+(1:na));
