Function File: lut = makelut (fun, n)
Function File: lut = makelut (fun, n, P1, P2, …)

Create a lookup table which can be used by applylut.

lut = makelut(fun,n) returns a vector which can be used by applylut as a lookup table.

fun can be a function object as created by inline, or simply a string which contains the name of a function. fun should accept a n-by-n matrix whose elements are binary (0 or 1) and returns an scalar (actually anything suitable to be included in a vector).

makelut calls fun with all possible matrices and builds a vector with its result, suitable to be used by applylut. The length of this vector is 2^(n^2), so 16 for 2-by-2 and 512 for 3-by-3.

makelut also passes parameters P1, P2, .... to fun.

See also: applylut.

Demonstration 1

The following code

 makelut(@(x) sum(x(:))>=3, 2)
 % Returns '1' if one or more values
 % in the input matrix are 1

Produces the following output

ans =

   0
   0
   0
   0
   0
   0
   0
   1
   0
   0
   0
   1
   0
   1
   1
   1

Package: image