在matlab中量化dct系数

时间:2010-05-15 10:09:28

标签: matlab image-processing

你好我需要为一个块执行图像的dct系数的量化 在matlab中大小为8 * 8像素。你能帮我解释一下语法吗,谢谢你。

4 个答案:

答案 0 :(得分: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 :(得分: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)

答案 2 :(得分: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

答案 3 :(得分:0)

malloc