Documentation

This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

applylut

Neighborhood operations on binary images using lookup tables

`applylut` is not recommended. Use `bwlookup` instead.

Syntax

```A = applylut(BW,LUT) ```

Description

`A = applylut(BW,LUT)` performs a 2-by-2 or 3-by-3 neighborhood operation on binary image `BW` by using a lookup table (`LUT`). `LUT` is either a 16-element or 512-element vector returned by `makelut`. The vector consists of the output values for all possible 2-by-2 or 3-by-3 neighborhoods.

Class Support

`BW` can be numeric or logical, and it must be real, two-dimensional, and nonsparse. `LUT` can be numeric or logical, and it must be a real vector with 16 or 512 elements. If all the elements of `LUT` are `0` or `1`, then `A` is logical. If all the elements of `LUT` are integers between 0 and 255, then `A` is `uint8`. For all other cases, `A` is `double`.

Examples

collapse all

Create the LUT.

``` lutfun = @(x)(sum(x(:))==4); lut = makelut(lutfun,2);```

Read image into the workspace and then apply the LUT to the image. An output pixel is `on` only if all four of the input pixel's neighborhood pixels are `on` .

``` BW1 = imread('text.png'); BW2 = applylut(BW1,lut);```

Show the original image and the eroded image.

` figure, imshow(BW1);`

` figure, imshow(BW2);`

Algorithms

collapse all

`applylut` performs a neighborhood operation on a binary image by producing a matrix of indices into `lut`, and then replacing the indices with the actual values in `lut`. The specific algorithm used depends on whether you use 2-by-2 or 3-by-3 neighborhoods.

2-by-2 Neighborhoods

For 2-by-2 neighborhoods, `length(lut)` is 16. There are four pixels in each neighborhood, and two possible states for each pixel, so the total number of permutations is 24 = 16.

To produce the matrix of indices, `applylut` convolves the binary image `BW` with this matrix.

```8 2 4 1```

The resulting convolution contains integer values in the range [0,15]. `applylut` uses the central part of the convolution, of the same size as `BW`, and adds 1 to each value to shift the range to [1,16]. It then constructs `A` by replacing the values in the cells of the index matrix with the values in `lut` that the indices point to.

3-by-3 Neighborhoods

For 3-by-3 neighborhoods, `length(lut)` is 512. There are nine pixels in each neighborhood, and two possible states for each pixel, so the total number of permutations is 29 = 512.

To produce the matrix of indices, `applylut` convolves the binary image `BW` with this matrix.

```256 32 4 128 16 2 64 8 1```

The resulting convolution contains integer values in the range [0,511]. `applylut` uses the central part of the convolution, of the same size as `BW`, and adds 1 to each value to shift the range to [1,512]. It then constructs `A` by replacing the values in the cells of the index matrix with the values in `lut` that the indices point to.