Blockproc error when including BorderSize argument

1 vue (au cours des 30 derniers jours)
Stewart Tan
Stewart Tan le 8 Août 2019
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 commentaires
Adam
Adam le 8 Août 2019
Modifié(e) : Adam le 8 Août 2019
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 le 8 Août 2019
So is it not possible to apply dct with included borders? Do you have any suggestion on this?

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Août 2019
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.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by