Blockproc error when including BorderSize argument

1 回表示 (過去 30 日間)
Stewart Tan
Stewart Tan 2019 年 8 月 8 日
回答済み: Walter Roberson 2019 年 8 月 8 日
and i ran the following code:
I = imread('cameraman.tif');
I = im2double(I);
imshow(I)
T = dctmtx(8);
dct = @(block_struct) T * block_struct.data * T';
B = blockproc(I,[8 8],dct,'BorderSize',[4 4],'Trim',false) %modification made here
The code was from the link above, but i included the 'BorderSize' criteria to allow for overlapping of the blocks. Upon running the code, i get the error saying:
Error using blockprocFunDispatcher
BLOCKPROC encountered an error while evaluating the user-supplied function handle,FUN.
Error in blockprocInMemory
[u1_output fun_nargout] = blockprocFunDispatcher(fun,block_struct,...
Error in blockproc
result_image = blockprocInMemory(source,fun,options);
What could be the issue causing the error message above? If i remove 'BorderSize',[4 4], 'Trim',false it works as normal like in the link but am i using it wrongly?
  2 件のコメント
Adam
Adam 2019 年 8 月 8 日
編集済み: Adam 2019 年 8 月 8 日
T is hard-coded to be of size 8 by 8.
You have now added a [4 4] border to your 8 by 8 blocks so they cannot multiply by T any more because they are not the same size.
Stewart Tan
Stewart Tan 2019 年 8 月 8 日
So is it not possible to apply dct with included borders? Do you have any suggestion on this?

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2019 年 8 月 8 日
I = imread('cameraman.tif');
I = im2double(I);
T = dctmtx(8);
dct = @(block_struct) T * block_struct.data * T';
B = blockproc(I,[4 4],dct,'BorderSize',[2 2],'Trim',false, 'padpartial', true); %modification made here
size(I)
size(B)
Note that B comes out larger than I because you have trim set to false.
Notice the pad partial being needed: without it then when you reach the edge of the image, you run off the edge. blockproc() keeps moving the window until the last of the [4 4] windows is at the right (or bottom) edge, leaving the specified border padding "hanging over" the end of the image.

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by