Blockproc error when including BorderSize argument

1 次查看(过去 30 天)
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