function a = idct2(arg1,mrows,ncols)
%IDCT2	Two-dimensional inverse discrete cosine transform.
%	A = IDCT2(B) inverts the DCT transform, returning the
%	original matrix if B was obtained using B = DCT2(A).
%
%	A = IDCT2(B,[M N]) or A = IDCT2(B,M,N) pads the matrix
%	B to size M-by-N before transforming.  B is cropped
%	if [M N] < size(B).
%
%	See also FFT2,IFFT2,DCT2.

%	Clay M. Thompson 10-6-92
%	Copyright (c) 1992 by The MathWorks, Inc.
%	$Revision: 1.9 $  $Date: 1993/09/09 22:58:07 $

% Reference: "Two-dimensional Signal and Image Processing" by
% Jae S. Lim, pp. 148-162.  Implements an even-symmetrical IDCT.

[m, n] = size(arg1);
% Basic algorithm.
if (nargin == 1) & (m > 1) & (n > 1)
    a = idct(idct(arg1).').';
    return;
end

% Padding for vector input.

b = arg1;
if nargin==2, ncols = mrows(2); mrows = mrows(1); end
mpad = mrows; npad = ncols;
if m == 1 & mpad > m, b(2, 1) = 0; m = 2; end
if n == 1 & npad > n, b(1, 2) = 0; n = 2; end
if m == 1, mpad = npad; npad = 1; end   % For row vector.

% Transform.

a = idct(b, mpad);
if m > 1 & n > 1, a = idct(a.', npad).'; end
