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