MATLAB Answers

Getting many outputs using blockproc

조회 수: 20(최근 30일)
Youssra
Youssra 2015년 7월 18일
답변: Eric Chadwick 2018년 3월 21일
I want to apply SVD for each 4*4 blocks using the "blockproc" and get 3 outputs: U, S and V so I can reconstract all blocks together again but Matlab gets me "too many ouput arguments". How can I solve this problem?
fun = @(block_struct) svd(block_struct.data);
[U S V] = blockproc(a, [4 4], fun)
This is the error that I have:
Error using blockproc
Too many output arguments.

채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 18일
No, this is not possible with blockproc().
You can use something like
function r = blocksvd(block_struct)
[U, S, V] = svd(block_struct.data);
Spad = nan(size(U));
Vpad = Spad;
Spad(1:size(S,1),1:size(S,2)) = S;
Vpad(1:size(U,1),1:size(U,2)) = U;
r = [U; Spad; Vpad];
end
this returns a 12 x 4 array that can be broken up again into U, S, V.
  댓글 수: 3
Youssra
Youssra 2015년 7월 21일
No, I didn't. I just add this line to be sure if I will get the original values from returned U, Spad and Vpad. just like that:
function r = blocksvd(block_struct)
[U, S, V] = svd(block_struct.data);
Spad = nan(size(U));
Vpad = Spad;
Spad(1:size(S,1),1:size(S,2)) = S;
Vpad(1:size(U,1),1:size(U,2)) = U;
r = [U; Spad; Vpad];
img_back=U*Spad*Vpad'
end
I get a matrix with the same size as the original but not the same values. is this wrong?

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Brett Shoelson
Brett Shoelson 2017년 8월 15일
편집: Walter Roberson 2017년 8월 15일
Walter is correct that blockproc returns a single output. For clarity, though, it's worth pointing out that you can make n separate calls to blockproc, requesting args 1--n. That's tricky to do with a one-line function handle, but easy if you create a single-output function for each output that you want to generate, and call them sequentially for the image. (Not ideal, but maybe helpful.)
For instance, if you wanted to calculate the thresholdOutput of the edge(img,'LOG') function:
[~,threshOut] = edge(img,'LOG');
you could create a function called, for example, calculateEdgeThresh, with a syntax like:
function thresh = calculateEdgeThresh(img)
[~,thresh] = edge(img,'LOG');
then (in pseudo-code):
localEdgeFcn = @(x) edge(x.data,'LOG');
threshFcn = @(x) calculateEdgeThresh(x.data);
localEdge = blockproc(img,localEdgeFcn); %This one is a one-liner, via function handle
localThresh = blockproc(img,threshFcn); %This one requires the separate calculateEdgeThresh function
Cheers,
Brett
  댓글 수: 3
Image Analyst
Image Analyst 2018년 3월 20일
Eric, blockproc() stitches it back together automatically. See my attached demos.

댓글을 달려면 로그인하십시오.


Eric Chadwick
Eric Chadwick 2018년 3월 21일
Hello, thank you both for responding so quickly! My function does have outputs, I just did not show them when I showed my function to you. However when I went to copy and paste it just now, I realized I wasn't telling it to output the image my function normally outputs. Adding the image as an output has solved the problem.
Thank you both!
Cheers,
Eric

Community Treasure Hunt

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

Start Hunting!

Translated by