Main Content

bwlookup

Nonlinear filtering using lookup tables

Description

A = bwlookup(BW,lut) performs a 2-by-2 or 3-by-3 nonlinear neighborhood filtering operation on binary image BW. The neighborhood processing determines an integer index value used to access values in lookup table lut. The fetched lut value becomes the pixel value in output image A at the targeted position.

example

Examples

collapse all

Construct a lookup table lut such that the filtering operation places a 1 at the targeted pixel location in the input image only when all four pixels in the 2-by-2 neighborhood of BW are set to 1.

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

Load a binary image.

BW1 = imread("text.png");

Perform 2-by-2 neighborhood processing with 16-element vector lut.

BW2 = bwlookup(BW1,lut);

Display the original and eroded image.

h1 = subplot(1,2,1); imshow(BW1); title("Original Image")
h2 = subplot(1,2,2); imshow(BW2); title("Eroded Image")

Figure contains 2 axes objects. Hidden axes object 1 with title Original Image contains an object of type image. Hidden axes object 2 with title Eroded Image contains an object of type image.

Zoom in to see the effects of erosion on the text.

set(h1,Ylim=[1 64],Xlim=[1 64]);
set(h2,Ylim=[1 64],Xlim=[1 64]);

Figure contains 2 axes objects. Hidden axes object 1 with title Original Image contains an object of type image. Hidden axes object 2 with title Eroded Image contains an object of type image.

Input Arguments

collapse all

Binary image to be transformed by the nonlinear neighborhood filtering operation, specified as a 2-D logical matrix or 2-D numeric matrix. For numeric input, any nonzero pixels are considered to be 1 (true).

Lookup table of output pixel values, specified as a 16- or 512-element vector. The size of lut determines which of the two neighborhood operations is performed. You can use the makelut function to create a lookup table.

  • If lut contains 16 data elements, then the neighborhood matrix is 2-by-2.

  • If lut contains 512 data elements, then the neighborhood matrix is 3-by-3.

Output Arguments

collapse all

Output image, returned as a logical matrix or numeric matrix of the same size as the input image BW. The pixel values are determined by the content of the lookup table, lut, and are of the same data type as lut.

Algorithms

collapse all

The bwlookup function performs these steps to determine the value of each pixel in the processed image A:

  • Locate the pixel neighborhood in input image BW based on the coordinates of the target pixel in A. The function zero-pads border pixels of image BW when the neighborhood extends past the edge of BW.

  • Calculate an index, idx, based on the binary pixel pattern of the neighborhood.

  • Set the target pixel in A as the value of the lookup table at the index idx, in other words, the value of lut(idx).

For an example that demonstrates each step of the algorithm, see Look Up Value of Sample Pixel.

Extended Capabilities

expand all

Version History

Introduced in R2012b

expand all

See Also