主要内容

dct

离散余弦变换

说明

y = dct(x) 返回输入数组 x 的酉离散余弦变换。输出 y 具有与 x 相同的大小。如果 x 具有多个维度,则 dct 沿大小大于 1 的第一个数组维度进行运算。

示例

y = dct(x,n) 在变换之前将 x 的相关维度零填充到或截断为长度 n

y = dct(x,n,dim) 沿维度 dim 计算变换。要输入维度并使用 n 的默认值,请将第二个参量指定为空,即 []

示例

y = dct(___,Type=dcttype) 指定要计算的离散余弦变换的类型。有关详细信息,请参阅 离散余弦变换。此选项可以与上述任一语法组合使用。

示例

示例

全部折叠

查找表示序列中 99% 能量的 DCT 系数数量。

x = (1:100) + 50*cos((1:100)*2*pi/40).^3;
X = dct(x);
[XX,ind] = sort(abs(X),"descend");
i = 1;
while (norm(X(ind(1:i)))/norm(X))^2 < 0.99
   i = i + 1;
end
needed = i;

重新构造信号并将其与原始信号比较。

X(ind(needed+1:end)) = 0;
xx = idct(X);

plot([x;xx]')
legend("Original","Reconstructed, N = " + needed, ...
       Location='SouthEast')

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent Original, Reconstructed, N = 4.

加载一个文件,其中包含用于铸造美国便士的模具深度测量值。数据取自美国国家标准与技术研究院,在 128×128 网格上采样。显示数据。

load penny

surf(P)
view(2)
colormap copper
shading interp
axis ij square off

Figure contains an axes object. The hidden axes object contains an object of type surface.

计算图像数据的离散余弦变换。首先沿行进行运算,然后沿列进行运算。

Q = dct(P,[],1);
R = dct(Q,[],2);

查找包含图像中 99.98% 能量的 DCT 系数比例。

X = R(:);

[~,ind] = sort(abs(X),"descend");
coeffs = 1;
while (norm(X(ind(1:coeffs)))/norm(X))^2 < 0.9998
   coeffs = coeffs + 1;
end
disp(coeffs + " of " + numel(R) + " coefficients are sufficient")
5215 of 16384 coefficients are sufficient

仅使用必要的系数重新构造图像。

R(abs(R) < abs(X(ind(coeffs)))) = 0;

S = idct(R,[],2);
T = idct(S,[],1);

显示重构图像。

surf(T)
view(2)
shading interp
axis ij square off

Figure contains an axes object. The hidden axes object contains an object of type surface.

加载一个文件,其中包含用于铸造美国便士的模具深度测量值。数据取自美国国家标准与技术研究院,在 128×128 网格上采样。显示数据。

load penny

surf(P)
colormap copper
shading interp
view(2)
axis ij square off

Figure contains an axes object. The hidden axes object contains an object of type surface.

使用 DCT-1 变体计算图像数据的离散余弦变换。首先沿行进行运算,然后沿列进行运算。

Q = dct(P,[],1,Type=1);
R = dct(Q,[],2,Type=1);

执行逆变换。截断逆变换,使重新构造图像的每个维度是原始长度的一半。

S = idct(R,size(P,2)/2,2,Type=1);
T = idct(S,size(P,1)/2,1,Type=1);

再次执行逆变换。对逆变换使用零填充,使重新构造图像的每个维度是原始长度的两倍。

U = idct(R,size(P,2)*2,2,Type=1);
V = idct(U,size(P,1)*2,1,Type=1);

显示原始图像和重新构造图像。

surf(V)
hold on
surf(P)
surf(T)
hold off

shading interp
view(2)
axis ij equal off

Figure contains an axes object. The hidden axes object contains 3 objects of type surface.

输入参数

全部折叠

输入数组,指定为实数值或复数值向量、矩阵或 N 维数组。

示例: sin(2*pi*(0:255)/4) 将正弦波指定为行向量。

示例: sin(2*pi*[0.1;0.3]*(0:39))' 指定一个双通道正弦波。

数据类型: single | double
复数支持:

变换长度,指定为正整数标量。

数据类型: single | double

沿其运算的维度,指定为正整数标量。

数据类型: single | double

离散余弦变换类型,指定为 1 到 4 的正整数标量。请参阅离散余弦变换了解不同类型 DCT 的定义。

数据类型: single | double

输出参量

全部折叠

离散余弦变换,以实数值或复数值向量、矩阵或 N 维数组形式返回。

详细信息

全部折叠

参考

[1] Jain, A. K. Fundamentals of Digital Image Processing. Englewood Cliffs, NJ: Prentice-Hall, 1989.

[2] Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. 2nd Ed. Upper Saddle River, NJ: Prentice Hall, 1999.

[3] Pennebaker, W. B., and J. L. Mitchell. JPEG Still Image Data Compression Standard. New York: Van Nostrand Reinhold, 1993.

扩展功能

全部展开

版本历史记录

在 R2006a 之前推出

另请参阅

| | (Image Processing Toolbox) | (Image Processing Toolbox)