2010-05-15 78 views

回答

1

在MATLAB中有一个用于DCT的内置函数。

您需要信号处理工具箱。在MATLAB命令中输入'ver'(不带引号)来查看是否有。

代码:

image = image; % define your image 

[m,n] = size(image); % get size of your image 

imvector = reshape(image, m*n, 1); % reshape your image to a vector to compute DCT 

imdct = dct(imvector); % compute DCT 

imagedct = reshape(imdct,m,n); \ reshape result back to original form of your image 
1

有在帮助文件中的一个例子,以及这是非常好的:

I = imread('cameraman.tif'); 
I = im2double(I); 
T = dctmtx(8); 
dct = @(block_struct) T * block_struct.data * T'; 
B = blockproc(I,[8 8],dct); 
mask = [1 1 1 1 0 0 0 0 
     1 1 1 0 0 0 0 0 
     1 1 0 0 0 0 0 0 
     1 0 0 0 0 0 0 0 
     0 0 0 0 0 0 0 0 
     0 0 0 0 0 0 0 0 
     0 0 0 0 0 0 0 0 
     0 0 0 0 0 0 0 0]; 
B2 = blockproc(B,[8 8],@(block_struct) mask .* block_struct.data); 
invdct = @(block_struct) T' * block_struct.data * T; 
I2 = blockproc(B2,[8 8],invdct); 
imshow(I), figure, imshow(I2) 
0

量化DCT系数,您只需通过一个量化项将每个系数并整数到整数。量化项对于每个系数通常是唯一的,并且存储在量化矩阵中。

Wikipedia has a nice example.以下是如何在Matlab中实现该示例。

coef = [ 
-415 -33 -58 35 58 -51 -15 -12; 
    5 -34 49 18 27 1 -5 3; 
    -46 14 80 -35 -50 19 7 -18; 
    -53 21 34 -20 2 34 36 12; 
    9 -2 9 -5 -32 -15 45 37; 
    -8 15 -16 7 -8 11 4 7; 
    19 -28 -2 -26 -2 7 -44 -21; 
    18 25 -12 -44 35 48 -37 -3 
    ]; 

quant = [ 
16 11 10 16 24 40 51 61; 
12 12 14 19 26 58 60 55; 
14 13 16 24 40 57 69 56; 
14 17 22 29 51 87 80 62; 
18 22 37 56 68 109 103 77; 
24 35 55 64 81 104 113 92; 
49 64 78 87 103 121 120 101; 
72 92 95 98 112 100 103 99 
    ]; 

quantCoef = round(coef ./ quant) 

quantCoef = 
    -26 -3 -6  2  2 -1  0  0 
    0 -3  4  1  1  0  0  0 
    -3  1  5 -1 -1  0  0  0 
    -4  1  2 -1  0  0  0  0 
    1  0  0  0  0  0  0  0 
    0  0  0  0  0  0  0  0 
    0  0  0  0  0  0  0  0 
    0  0  0  0  0  0  0  0