-1

以下代码未在 matlab 中运行。我正在 matlab 中尝试一个匿名函数。你能告诉我这行有什么问题吗:

Inv_Y_Quant = blockproc(BB,[8 8], InvQuant);

相关代码如下:

clear all
clc

I = imread('cameraman.tif');
% convert it to double
I = im2double(I);
% "Trim by 128"
I = I-128;
% Generate the DCT matrix
T = dctmtx(8);
% Generate Function handler for DCT
MyFun1 = @(block_struct) T * block_struct.data * T';
% BlockProcess the DCT the function for 8 by 8 blocks
B = blockproc(I,[8 8],MyFun1);
% Form the Quantization matrix
Q = [ 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];
% now generate function handler for the quantization
MyFun2 = @(block_struct)block_struct.data ./Q;
% perform the quantization
BB = blockproc(B,[8 8],MyFun2);
InvQuant = @(block_struct)round(block_struct.data.*Q);
Inv_Y_Quant = blockproc(BB,[8 8], InvQuant);
InvDct = @(block_struct)dct_matrix'*block_struct.data*dct_matrix;
Z = blockproc(Inv_Y_Quant, [8 8], InvDct);
Z = Z+128;
figure, imshow(Z)
Z = uint8(Z);
figure, imshow(Z)

%imwrite(Z, 'Mar7.tif');
%b = imread('Mar7.tif');
%imshow(b)
4

1 回答 1

1

正如您在评论中所写,问题是您尝试dct_matrix在匿名函数中使用数组InvDct。该数组从未在您的代码中定义。

您是否打算使用矩阵T(init as dctmtx(8))?

编辑:
在匿名函数中使用参数时(如dct_matrix本例所示),应在定义匿名函数之前定义这些参数。

于 2013-04-24T11:56:38.307 回答