📄 makelut.m
字号:
function lut = makelut(varargin)
%MAKELUT Construct lookup table for use with APPLYLUT.
% LUT = MAKELUT(FUN,N) returns a lookup table for use with
% APPLYLUT. FUN is either a string containing the name of a
% function or an inline function object. The function should
% take a 2-by-2 or 3-by-3 matrix of 1's and 0's as input and
% return a scalar. N is either 2 or 3, indicating the size of
% the input to FUN. MAKELUT creates LUT by passing all
% possible 2-by-2 or 3-by-3 neighborhoods to FUN, one at a
% time, and constructing either a 16-element vector (for 2-by-2
% neighborhoods) or a 512-element vector (for 3-by-3
% neighborhoods). The vector consists of the output from FUN
% for each possible neighborhood.
%
% LUT = MAKELUT(FUN,N,P1,P2,...) passes the additional
% parameters P1, P2, ..., to FUN.
%
% Class Support
% -------------
% LUT is returned as a vector of class double.
%
% Example
% -------
% f = inline('sum(x(:)) >= 2');
% lut = makelut(f,2);
%
% See also APPLYLUT.
% Steven L. Eddins, March 1996
% Copyright 1993-1998 The MathWorks, Inc. All Rights Reserved.
% $Revision: 1.10 $ $Date: 1997/11/24 15:35:51 $
if (nargin < 2)
error('Too few input arguments');
end
fun = varargin{1};
n = varargin{2};
params = varargin(3:end);
fun = fcnchk(fun, length(params));
if (n == 2)
lut = zeros(16,1);
for k = 1:16
a = reshape(fliplr(dec2bin(k-1,4) == '1'), 2, 2);
lut(k) = feval(fun, a, params{:});
end
elseif (n == 3)
lut = zeros(512,1);
for k = 1:512
a = reshape(fliplr(dec2bin(k-1,9) == '1'), 3, 3);
lut(k) = feval(fun, a, params{:});
end
else
error('N must be 2 or 3');
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -