how can i use dct2 function in blockproc to avoid the following error 'cant convert struct from double'?

> I = rgb2gray(image1.png);
> myfun= @dct2;
> B = blockproc(I,[8 8],myfun);
These are the errors I get:
> Error using double
> Conversion to double from struct is not possible.
> Error in dct (line 28)
> a = double(a);
> Error in dct2 (line 68)
> b = dct(a, mpad);
> Error in blockprocFunDispatcher (line 14)
> output_block = fun(block_struct);
> Error in blockprocInMemory (line 81)
> [ul_output fun_nargout] =
> blockprocFunDispatcher(fun,block_struct,...
>
> Error in blockproc (line 237)
> result_image = blockprocInMemory(source,fun,options);
Can someone explain why these errors??

 채택된 답변

I was able to re-create your issue however the first step
I = rgb2gray(image1.png);
I was not able to convert directly from a png file with rgb2gray but rather I had to do
J = imread(image1.png)
I = rgb2gray(J);
Assuming your first 2 inputs are formatted how you want them, looking at the blockproc documentation:
It seems your issue is with the function handle input for dct2, according to the documentation the function input for blockproc should be a “Function handle to a function that accepts a block struct as input and returns a matrix, vector, or scalar.” Looking at the first example on the blockproc documentation page you should try something like this.
myfun = @(block_struct) dct2(block_struct.data);
Using this format fixed the ‘can’t convert struct from double’ error on my end.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2017년 7월 28일

편집:

2017년 7월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by