Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two outputs with blockproc

Tags:

matlab


I have this function that calculates the value of the binary pattern of a 3*3 block which result form thresholding the 8 neighbers pixels with the center pixel and returns two outputs: the decimal value of the binary code, the same decimal value if it's uniform or 59 if not.

function [out1,out2] = lbpblock(im)
%... implementation details
out1 = decimal ;
out2 = uniform;
end

The problem is when trying to use blockproc like this

result = blockproc(im,[3 3],@lbpblock);

the result array is only two dimensions (eg. 85*85) and has only the first output.

when I tried

[res1 res2] = blockproc(im,[3 3],@lbpblock); 

I get "Error using ==> blockproc Too many output arguments".
I tried to change the function signature

function out = lbpblock(im)
%... implementation details
out = [decimal, uniform];
end

the result array again two dimensions only but now (85*170) the first output is stored in odd columns and the second in even ones.
Is there any trick to get blockproc to store the result in a 85*85*2 array??

like image 984
Hassan Ajk Avatar asked Apr 15 '26 07:04

Hassan Ajk


1 Answers

You can achieve an NxNx2 array as output by concatenating in the third dimension.

Example:

im = magic(10);
r = blockproc(im, [3, 3], @func);

function r = func(im)
r1 = mean(im.data(:));
r2 = std(im.data(:));
r = cat(3, r1, r2);
end

The important line is cat(3, output1, output2).

like image 67
Trilarion Avatar answered Apr 16 '26 22:04

Trilarion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!