Filter löschen
Filter löschen

Undefined function 'mtimes' for input arguments of type 'struct'. Error in @(a)T*a*T' Error in blockprocFunDispatcher (line 13)

2 Ansichten (letzte 30 Tage)
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);

Antworten (1)

dpb
dpb am 4 Mai 2016
Bearbeitet: dpb am 4 Mai 2016
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 Kommentare
murat alboga
murat alboga am 4 Mai 2016
Sorry dbp, Thanks your answers. I added my little code. If you want to check again my code problems.
dpb
dpb am 4 Mai 2016
Bearbeitet: dpb am 4 Mai 2016
Ah, that's easier -- see updated Answer.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by