cv.dct - MATLAB File Help |
Performs a forward or inverse discrete Cosine transform of 1D or 2D array
dst = cv.dct(src)
dst = cv.dct(src, 'OptionName',optionValue, ...)
src
.The function cv.dct performs a forward or inverse discrete Cosine transform (dct) of a 1D or 2D floating-point array:
Forward Cosine transform of a 1D vector of N elements:
Y = CN * X
where
CN(j,k) = sqrt(alpha_j/N) * cos((pi*(2k+1)*j)/2N)
and alpha_0=1
, alpha_j=2
for j>0
.
Inverse Cosine transform of a 1D vector of N elements:
X = inv(CN) * Y = transpose(CN) * Y
(since CN
is an orthogonal matrix, CN * transpose(CN) = I
)
Forward 2D Cosine transform of MxN matrix:
Y = CN * X * transpose(CN)
Inverse 2D Cosine transform of MxN matrix:
X = transpose(CN) * X * CN
The function chooses the mode of operation by looking at the transformation flags and size of the input array:
Inverse = true
, the function does a forward 1D or 2D transform.
Otherwise, it is an inverse 1D or 2D transform.Rows = true
, the function performs a 1D transform of each row.Note: Currently cv.dct supports even-size arrays (2, 4, 6, etc.). For data
analysis and approximation, you can pad the array when necessary. Also, the
function performance depends very much, and not monotonically, on the array
size (see cv.getOptimalDFTSize). In the current implementation, dct of a
vector of size N
is calculated via DFT of a vector of size N/2
. Thus,
the optimal dct size N1 >= N
can be calculated as:
function N1 = getOptimalDCTSize(N)
N1 = 2 * cv.getOptimalDFTSize(fix((N+1)/2));
end