2013-04-24 96 views
-1

下面的代碼沒有在matlab中運行。我想在matlab.Can匿名函數請你告訴我,什麼是錯在這條線: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) 
+5

Matlab給你什麼錯誤?究竟是什麼問題? – Shai 2013-04-24 11:50:12

+0

錯誤的原因是: 未定義的函數或變量'dct_matrix'。 錯誤==> @(block_struct)dct_matrix'* block_struct.data * dct_matrix 錯誤==> blockprocFunDispatcher在14 output_block =樂趣(block_struct); 錯誤==> blockprocInMemory在71 [ul_output fun_nargout] = blockprocFunDispatcher(樂趣,block_struct,... 錯誤==> blockproc在248 result_image = blockprocInMemory(一,BLOCK_SIZE,樂趣,border_size, ... 錯誤在==> matlab5在31 Z = blockproc(Inv_Y_Quant,[8 8],InvDct); – 2013-04-24 11:53:14

回答

1

,正如你在評論中寫道,這一問題是您嘗試在匿名函數InvDct中使用數組dct_matrix。這個數組在您的代碼中定義爲從不

您是否打算使用矩陣T(init爲dctmtx(8))?

編輯:
當使用匿名函數的參數(如在該示例中dct_matrix),被定義匿名函數之前這些參數應該被定義。

+0

可以告訴我whr和hw shld我定義數組??謝謝 – 2013-04-24 11:59:36

+2

我不是語言純粹主義者,但寫標準英語而不是街道塊呢? – fpe 2013-04-24 12:07:47

+0

@AkshayaGangineni - 請參閱我的編輯 – Shai 2013-04-24 13:05:58