The first step in each iteration of the filtering operation
performed by bwlookup
entails computing the index
into
vector lut
based on the binary pixel pattern
of the neighborhood matrix on image BW
. The value
in lut
accessed at index
, lut(index)
,
is inserted into output image A
at the targeted
pixel location. This results in image A
being
the same data type as vector lut
.
Since there is a 1-to-1 correspondence in targeted pixel locations,
image A is the same size as image BW
. If the
targeted pixel location is on an edge of image BW
and
if any part of the 2-by-2 or 3-by-3 neighborhood matrix extends beyond
the image edge, then these non-image locations are padded with 0 in
order to perform the filtering operation.
The following figures show the mapping from binary 0 and 1 patterns
in the neighborhood matrices to its binary representation. Adding
1 to the binary representation yields index
which
is used to access lut
.
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 2^{4} =
16.
To illustrate, this example shows how the pixel pattern in a
2-by-2 matrix determines which entry in lut
is
placed in the targeted pixel location.
Create random 16-element lut
vector
containing uint8
data.
lut =
208
231
32
233
161
25
71
139
244
246
40
248
244
124
204
36
Create a 2-by-2 image and assume for this example
that the targeted pixel location is location BW(1,1)
.
By referring to the color coded mapping figure above,
the binary representation for this 2-by-2 neighborhood can be computed
as shown in the code snippet below. The logical 1 at BW(1,1)
corresponds
to blue in the figure which maps to the Least Signficant Bit (LSB)
at position 0 in the 4-bit binary representation (,2^{0}=
1). The logical 1 at BW(2,2)
is red which maps
to the Most Significant Bit (MSB) at position 3 in the 4-bit binary
representation (2^{3}= 8) .
The above calculation predicts that output image A
should contain the value 246 at targeted position A(1,1)
.
A(1,1)
does in fact equal 246.
Note:
For a more robust way to perform image erosion, see function imerode . |
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 2^{9} =
512.
The process for computing the binary representation of 3-by-3
neighborhood processing is the same as shown above for 2-by-2 neighborhoods.