正如您所提到的,dct2 和 idct2 将为您完成大部分工作。那么剩下的问题是:什么是高频内容,什么是低频内容?二维变换后的系数实际上将分别代表两个频率(一个在 x 方向,一个在 y 方向)。以下figure 显示了 8x8 discrete cosine transform 中每个系数的基数:
因此,可以用不同的方式回答低与高的问题。 JPEG encoding 中也使用了一种常见方式,如上图所示,从零频率沿对角线方向下降到最大值。正如我们在以下示例中看到的那样,这主要是因为自然图像主要位于“低”频率的“左上角”。当然值得看看dct2 的结果,并玩弄你的地区的实际选择高和低。
在下文中,我将频谱对角划分并绘制 DCT 系数 - 以对数刻度,否则我们只会在 (1,1) 附近看到一个大峰值。在示例中,我削减了一半以上的系数(可使用cutoff 调整),我们可以看到高频部分(“HF”)仍然包含一些相关的图像信息。如果将cutoff 设置为0 或以下,则只会留下小幅度的噪声。
%// Load an image
Orig = double(imread('rice.png'));
%// Transform
Orig_T = dct2(Orig);
%// Split between high- and low-frequency in the spectrum (*)
cutoff = round(0.5 * 256);
High_T = fliplr(tril(fliplr(Orig_T), cutoff));
Low_T = Orig_T - High_T;
%// Transform back
High = idct2(High_T);
Low = idct2(Low_T);
%// Plot results
figure, colormap gray
subplot(3,2,1), imagesc(Orig), title('Original'), axis square, colorbar
subplot(3,2,2), imagesc(log(abs(Orig_T))), title('log(DCT(Original))'), axis square, colorbar
subplot(3,2,3), imagesc(log(abs(Low_T))), title('log(DCT(LF))'), axis square, colorbar
subplot(3,2,4), imagesc(log(abs(High_T))), title('log(DCT(HF))'), axis square, colorbar
subplot(3,2,5), imagesc(Low), title('LF'), axis square, colorbar
subplot(3,2,6), imagesc(High), title('HF'), axis square, colorbar
(*) 关于tril 的注意事项:下三角函数相对于从左上角到右下角的数学对角线进行操作,因为我想要另一个对角线,我在前后左右翻转。
还要注意,这种操作通常不会应用于整个图像,而是应用于例如块8x8。看看blockproc 和this article。