Borrar filtros
Borrar filtros

I am trying to use blockproc (A,[8 8 ],dct2) to create a block of 8X8 from A image of 600X800 it does not works as they are telling me that dct2 is not a handle function . what is the exact argument I have to use instead of dct2?

6 visualizaciones (últimos 30 días)
A = imread('C:\lesloges.png'); B= rgb2gray(A); B=double(B)/255.0;
C= blockproc(B,[8 8],dct2);
Error using dct2 (line 45) Not enough input arguments.
Error in essaidecoupagebloc88 (line 11) C= blockproc(B,[8 8],dct2)
  2 comentarios
Geoff Hayes
Geoff Hayes el 29 de Mayo de 2014
According to http://www.mathworks.com/help/images/ref/blockproc.html#inputarg_fun, a function handle is required. Try putting an ampersand in front of dct2:
C= blockproc(B,[8 8],@dct2);
Note that if I do
y = @dct2;
then class(y) returns function_handle.
yaowu groshenry
yaowu groshenry el 30 de Mayo de 2014
thanks but is does not seem to work.I wrote:
A=imread('C:\Users\ygroshen\Desktop\fleurslesloges.png');
I=rgb2gray(A);
y=@dct2;
J= blockproc(I,[8 8],y);
imshow(J)
I have this error message:
Function BLOCKPROC encountered an error while evaluating the user supplied function handle, FUN.
The cause of the error was:
Error using double Conversion to double from struct is not possible.
Error in dct (line 27) a = double(a);
Error in dct2 (line 67) b = dct(a, mpad);
Error in blockprocFunDispatcher (line 13) output_block = fun(block_struct);
Error in blockprocInMemory (line 80) [ul_output fun_nargout] = blockprocFunDispatcher(fun,block_struct,...
Error in blockproc (line 236) result_image = blockprocInMemory(source,fun,options);
Error in codedJPEGavecIMTB (line 5) J= blockproc(I,[8 8],y);

Iniciar sesión para comentar.

Respuestas (2)

Geoff Hayes
Geoff Hayes el 30 de Mayo de 2014
The documentation for the blockproc function (see http://www.mathworks.com/help/images/ref/blockproc.html for details) indicates that the function handle must be to a function that accepts a block struct as input and returns a matrix, vector, or scalar. Your function, dct2, accepts a matrix only, not a structure. So you will have to do something like the example from the blockproc link:
% their example
fun = @(block_struct) imresize(block_struct.data,0.15);
% your code
fun = @(block_struct) dct2(block_struct.data);
J = blockproc(I,[8 8],fun);
Try the above and see if it helps.

Meshooo
Meshooo el 24 de Sept. de 2014
Hi Lu,
Check the following url, it shows a very good example for block processing.
Hope it helps you.
Meshoo

Community Treasure Hunt

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

Start Hunting!

Translated by