| Image Processing Toolbox™ | ![]() |
A = applylut(BW,LUT)
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.
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.
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.
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.
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.
Perform erosion using a 2-by-2 neighborhood. An output pixel is on only if all four of the input pixel's neighborhood pixels are on.
lut = makelut('sum(x(:)) == 4',2);
BW = imread('text.png');
BW2 = applylut(BW,lut);
imshow(BW), figure, imshow(BW2)

![]() | applycform | axes2pix | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |