Undefined function 'mtimes' for input arguments of type 'struct'. Error in @(a)T*a*T' Error in blockprocFunDispatcher (line 13)
1 次查看(过去 30 天)
显示 更早的评论
I am doing jpeg compression. I will imlement dct to image with blockproc. When I want to working the below code Matlab is giving that problem. Can you help me for solve this problem. After I will quantization process this code..
%
clc
clear all
close all
f = imread('monkey.tif');
g1 = rgb2gray(f);
g1 = im2double(g1);
%imshow(g1);
T = dctmtx(8);
dct_2 = @(x)T*x*T';
A = blockproc(g1, [8 8], dct_2);
0 个评论
回答(1 个)
dpb
2016-5-4
编辑:dpb
2016-5-4
You must reference the structure field content to have an array as input to the function. Example...
>> s.x=rand(2); % create a structure, fieldname 'x' as 2x2 array
>> abs(s) % take absolute value (I don't have Toolbox, same issue)
Undefined function 'abs' for input arguments of type 'struct'.
>> abs(s.x) % now refer to the field
ans =
0.2760 0.6551
0.6797 0.1626
>>
Or, you could have (perhaps inadvertently) created a nested structure that would cause same thing but at deeper level --
>> t.s=s % create structure containing structure
t =
s: [1x1 struct]
>> abs(t)
Undefined function 'abs' for input arguments of type 'struct'.
>> abs(t.s)
Undefined function 'abs' for input arguments of type 'struct'.
>> abs(t.s.x)
ans =
0.2760 0.6551
0.6797 0.1626
>>
We can't know what you did precisely w/o seeing the definition for the data and the actual code usage besides the error.
ADDENDUM
Ah, with the function handle definition in line it's easier to see/pick out the issue -- examples did illustrate the error, just not so simple to see what the root cause was--
Note the requirement that the function accept a block_struct
From the example for blockproc
fun = @(block_struct) imresize(block_struct.data,0.15);
So, your function needs to refer to x.data to refer to the data, x in the argument is the structure.
dct_2 = @(x)T*x.data*T';
2 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!