2010-05-15 5 views

Répondre

1

Il existe une fonction intégrée dans MATLAB pour DCT.

Vous avez besoin de la boîte à outils de traitement du signal. Tapez 'ver' (sans guillemets) dans la commande MATLAB pour voir si vous l'avez.

Le code:

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

Il y a un exemple dans le fichier d'aide et qui est très agréable:

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

Pour quantifier les coefficients TCD, vous suffit de diviser chaque coefficient par un terme de quantification et arrondir aux entiers. Les termes de quantification sont souvent uniques pour chaque coefficient et sont stockés dans une matrice de quantification.

Wikipedia has a nice example. Voici comment implémenter cet exemple dans 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