You are here : matlabImage Processingbwlookup

bwlookup() - Image Processing

A = bwlookup(BW,lut) performs
a 2-by-2 or 3-by-3 nonlinear neighborhood filtering operation on binary
or grayscale image BW and returns the results
in output image A. 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.A is the same size as BWA is the same data type as lutgpuarrayA = bwlookup(gpuarrayBW,lut) performs
the filtering operation on a GPU. The input image and output image
are gpuArrays. lut can be
a numeric or gpuArray vector. This syntax requires
the Parallel Computing Toolbox™.Code Generation support:
Yes.MATLAB Function Block support:
Yes.


Syntax

A = bwlookup(BW,lut) examplegpuarrayA = bwlookup(gpuarrayBW,lut)


Example

2-by-2 Neighborhood Erosion of Binary Image
Perform an erosion along the edges of a binary
image using a 2-by-2 neighborhood. Vector lut is
constructed such that the filtering operation places a 1 at the targeted
pixel location in image A only when all 4 pixels
in the 2-by-2 neighborhood of BW are set to 1.
For all other 2-by-2 neighborhood combinations in BW,
the targeted pixel location in image A is set to 0.
Construct lut so it is true only
when all four 2-by-2 locations equal 1.lutfun = @(x)(sum(x(:))==4);
lut = makelut(lutfun,2)
lut =

     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     1Load binary image.BW1 = imread('text.png');
Perform 2-by-2 neighborhood processing with 16-element
vector LUT.BW2 = bwlookup(BW1,lut);
Show zoomed before and after images.figure; 
h1 = subplot(1,2,1); imshow(BW1), axis off; title('BW1')
h2 = subplot(1,2,2); imshow(BW2); axis off; title('BW2')
 
% 16X zoom to see effects of erosion on text
set(h1,'Ylim',[.5 64.5]); set(h1,'Xlim',[.5 64.5]);
set(h2,'Ylim',[.5 64.5]); set(h2,'Xlim',[.5 64.5]);

2-by-2 Neighborhood Erosion of Binary Image Using GPU
Perform an erosion along the edges of a binary
image using a 2-by-2 neighborhood, running the code on a graphics
processing unit (GPU). 
Construct lut so it is true only when
all four 2-by-2 locations equal 1lut = makelut('sum(x(:))==4',2);
Load binary image.BW1 = imread('text.png');
Perform 2-by-2 neighborhood processing with 16-element
vector LUT. To run the code on a GPU, create a gpuArray to
contain the image.BW2 = bwlookup(gpuArray(BW1),lut);
Show zoomed before and after images.figure; 
h1 = subplot(1,2,1); imshow(BW1), axis off; title('BW1')
h2 = subplot(1,2,2); imshow(BW2); axis off; title('BW2')
 
% 16X zoom to see effects of erosion on text
set(h1,'Ylim',[.5 64.5]); set(h1,'Xlim',[.5 64.5]);
set(h2,'Ylim',[.5 64.5]); set(h2,'Xlim',[.5 64.5]);


Output / Return Value


Limitations


Alternatives / See Also


Reference