Created
December 24, 2013 03:02
-
-
Save mwgamera/8108259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function X = impeval(X, fun, varargin) | |
%IMPEVAL Evaluate point-wise transformation of multichannel image. | |
% | |
% function X = impeval(X, fun, ...) | |
% | |
% Given multidimensional matrix and a function, impeval calls the | |
% function with vectors along the last dimension of the matrix | |
% rearranged into columns of 2-D matrix as function's first argument. | |
% The function must return a matrix with the same number of columns | |
% which is then rearranged back into the shape of the original matrix | |
% (length along the last dimension might change). Any additional | |
% arguments are passed directly to the function. | |
% klg, Dec 2013 | |
S = size(X); | |
X = shiftdim(X, ndims(X)-1); | |
X = feval(fun, X(:,:), varargin{:}); | |
X = reshape(X.', [S(1:end-1), size(X,1)]); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment