Main Content

makelut

Create lookup table for use with bwlookup

Description

example

lut = makelut(fun,n) creates a lookup table. fun is a function that creates a numeric output from a binary neighborhood of size n-by-n. The function creates a lookup table by passing all possible neighborhoods to fun, one at a time, and storing the outputs in vector lut.

Use the lookup table with bwlookup to perform nonlinear neighborhood filtering.

Examples

collapse all

Create a lookup table for 2-by-2 neighborhoods. In this example, the function passed to makelut returns true if the number of 1s in the neighborhood is 2 or greater, and returns false otherwise.

f = @(x) (sum(x(:)) >= 2);
lut = makelut(f,2)
lut = 16×1

     0
     0
     0
     1
     0
     1
     1
     1
     0
     1
      ⋮

Input Arguments

collapse all

Function handle, specified as a handle. The function must accept an n-by-n binary matrix of 1s and 0s as input and return a scalar.

For more information about function handles, see Create Function Handle.

Neighborhood size for the lookup table, specified as 2 or 3.

Output Arguments

collapse all

Lookup table, returned as a 16-element numeric vector when n is 2, or a 512-element numeric vector when n is 3.

Data Types: double

Version History

Introduced before R2006a

See Also