Skip to content

Instantly share code, notes, and snippets.

@mwgamera
Created December 24, 2013 03:02
Show Gist options
  • Save mwgamera/8108259 to your computer and use it in GitHub Desktop.
Save mwgamera/8108259 to your computer and use it in GitHub Desktop.
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