function b=dct2(arg1,mrows,ncols)
%DCT2	Two-dimensional discrete cosine transform.
%	B = DCT2(A) returns the discrete cosine transform of A.
%	The matrix B is the same size as A and contains the
%	discrete cosine transform coefficients.
%
%	B = DCT2(A,[M N]) or B = DCT2(A,M,N) pads or cropped
%	the matrix A to size M-by-N before transforming. 
%
%	This transform can be inverted using IDCT2.
%
%	See also FFT2,IFFT2,IDCT2.

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

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

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

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

% Transform.

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