how to have more than one output for Anonymous Functions when I am using nlfilter

1 vue (au cours des 30 derniers jours)
So im using the example provided for nlfilter in MATLAB:
A = imread('cameraman.tif');
A = im2double(A);
fun = @(x) median(x(:));
B = nlfilter(A,[3 3],fun);
imshow(A), figure, imshow(B)
I am wondering how can I define a function that has more than one input, meaning that if I want instead of just median have also the mean, is there anyway that the B matrix become N1*N2*2 instead of being N1*N2
Or for example a more complete version of my question is that how I can have this:
fun = @(x) (sort(x(:))) ;
B= nlfilter(A,[3 3],fun);
when B is N1*N2*9, and N1 and N2 are the size of the image

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Mai 2016
fun = @(x) { reshape(sort(x(:)), 1, 1, []) } ;
B = cell2mat( nlfilter(A, [3 3], fun) );

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