Texture Analysis with Langlet Transforms

advertisement
Texture Analysis with Langlet’s Transforms
Stuart Smith
stuart.smith3@comcast.net
Introduction
As was shown in [1] Langlet’s Helical and Cognitive transforms [2,3] can quickly and efficiently detect periodic
replications of bit patterns in boolean matrices that meet certain conditions. Consequently these transforms are able
to perform a sort of visual texture analysis on binary images. Among other capabilities, the transforms can extract
the “texture element,” that is, the bit pattern that is replicated in the horizontal and vertical directions to produce a
larger “texture image.” This is possible even if the replication is obscured by noise in the image to be analyzed.
Further, once the texture element has been extracted, it can be used by the transforms to reveal visual features buried
in the texture image. The texture processing functions described here are part of the Matlab Langlet Toolkit, which
can be downloaded from www.cs.uml.edu/~stu. The Toolkit Manual documents all of the functions in the Toolkit.
Basic Texture Analysis
The simplest case of texture analysis involves a square image composed of square texture elements. Suppose, for
example, we are given the 256×256 patch of texture shown in fig 1. On casual inspection it is obvious that the
texture is made up of repetitions of some smaller pattern or texture element. What is that pattern?
Fig. 1 Texture patch, 256×256 pixels
Assuming that the texture element has been repeated exactly across the entire image, we can get the answer in three
steps. First, the two-dimensional Helical transform (Toolkit function hel2) is applied to the image in fig. 1. The
result is shown in fig. 2. As can be seen, there is a 16×16 pixel subimage in an otherwise blank square in this figure.
This subimage is in effect a compressed encoding of the entire image. As will be shown next, fig. 1 consists of
instances of this subimage decoded and then concatenated vertically and horizontally.1
1 1
. Because the Helical transform is self-inverse, Fig. 1 can also be reconstructed from Fig. 2 simply by applying the
transform to the image represented by Fig. 2. This will not be possible with a noisy image.
Fig. 2 Two-dimensional Helical transform of Fig. 1
Next all the completely blank rows and columns are removed. Fig 3 shows the cropped picture, which is the encoded
texture element of Fig. 1.
Fig. 3 Zoomed-in view of the upper left corner of Fig. 2
Finally, to determine what the texture element is, the two-dimensional Helical transform is applied to the image
shown in fig. 3. The result is shown in fig. 4. The Toolkit function textile can reconstruct the image of Fig. 1 by
making a 16×16 square of tiles, each of which is an instance of the image in Fig. 4.
Fig. 4 Zoomed-in view of the calculated texture element of Fig. 1
In general, if a 2𝑛 × 2𝑛 binary image is composed exclusively of exact repetitions of a 2𝑚 × 2𝑚 binary subimage
(m<n), the two-dimensional Helical transform will extract a compressed encoding of the subimage. The subimage,
which is the texture element of the image, can then be recovered by stripping off the all-zeroes rows and columns
and then applying the Helical transform to the result. The full original image can then be reconstructed by making a
2𝑛−𝑚 × 2𝑛−𝑚 square of tiles, each of which is an instance of the calculated texture element.
Detecting Periodicity in Textures
When an image is composed of exact repetitions of a texture element, determining the texture element is simple and
straightforward, as was shown in the preceding section. It is more difficult when the image to be analyzed is not
composed of exact replications of the texture element, but rather contains a certain amount of noise or corrupted
pixels. In such cases additional processing is required. The first step is to determine the period of repetition of the
texture element. This is accomplished with the Toolkit function texcorrel, which is a sort of boolean
autocorrelation function. Suppose we are given the texture image of Fig. 5, which contains about 12% corrupted
pixels over the whole image.
Fig. 5 Texture image with 12% corrupt pixels
texcorrel provides both a plot of its result and an estimate of the periodicity in both the horizontal and vertical
directions. Applied to the image in Fig. 5, the texcorrel plot in Fig. 6 shows a peak every 16 steps, and the
function reports that it has determined that the periodicity is 16 in both the horizontal and vertical directions. Thus
the image shown in Fig. 5 must be composed of repetitions of a 16×16 texture element.
Fig. 6 texcorrel plot showing the periodicity of Fig. 5
Extracting The Texture Element
Once the periodicity of a noisy texture image has been determined, it is possible to calculate an estimated texture
element. In general, if a texture image has some given percentage of corrupted pixels, each subimage will also
contain about this same percentage of corrupted pixels. Thus, for example, any of the 16×16 subimages of Fig. 5
will likely contain about 12% noise. Although this means that we cannot be certain concerning exactly what texture
element was used to create the image in Fig. 5, it is nonetheless possible to do some interesting and useful work with
the estimated texture element. This will be shown in the next section.
The Toolkit procedure for calculating an estimated texture element for a noisy texture image is texfind. This
function uses texcorrel to determine the periodicity of the texture of Fig. 5 and hence the dimensions of its
underlying texture element. When the Helical transform is applied to Fig. 5, the result (Fig. 7) is not a nice, clean
picture like Fig. 2. The presence of noise in Fig. 5 causes the transform to spread over the entire image. Nonetheless,
once the periodicity of the texture is known, the subimage in the upper left corner (Fig 8) can be extracted. The
Helical transform is then applied to this result to obtain the estimated texture element (Fig. 9). The estimated texture
element can then be used to reconstruct an approximation of the image in Fig. 5. This new image (Fig. 10) consists
only of exact copies of the calculated texture element (Fig, 9).
Figure 7 Helical transform of Fig. 5
Fig. 8 Zoomed-in view of the Helical transform of estimated texture element of Fig. 5
Fig. 9 Zoomed-in view of the estimated texture element of Fig. 5
Finding Visual Features Buried in Noisy Textures
It turns out that there is a line drawing buried in Fig. 5. To discover it, we first need to construct a new texture image
from the texture element calculated above (Fig. 9) and depicted in Fig. 10. This is done with texfind.
Fig. 10 Image reconstructed from the estimated texture element of Fig. 9
To find the hidden line drawing, calculate a new image, original_image ≠ reconstructed_image, which has white
pixels in all positions where the two images are the same, and black pixels in all positions where they are different
(see Fig. 11). The Toolkit function texdetect performs all the necessary operations.
Fig. 11 Line drawing of an apple recovered from Fig. 5
Although there is a substantial amount of noise in Fig. 5, the line drawing of the apple is clearly visible in Fig. 11.
Fig. 11 itself is still noisy, but note the small blank square in the upper left corner. This is the location of the texture
element determined by texdetect. Since all the pixels at this location match exactly they will be all white. NB. If
the Cognitive transform is specified as the fn argument to texdetect, the white square will appear in the lower
right corner, but the picture as a whole will be otherwise indistinguishable from Fig. 11.
Non-Square Texture Elements and Backgrounds
The next level of difficulty in texture analysis is reached when either the background texture or the texture element,
or both, is not square. In such cases, the “standard” 2D Helical and Cognitive transforms as defined by Langlet
cannot simply be applied since these transforms work only on square images. The solution is a version of each
transform that works on vectors of any length. The Toolkit functions that do this are fanhel and fancog. The
Toolkit functions xhel and xcog are provided for the processing of two-dimensional objects such as images. Both
of these apply the 1D function to each row of its argument and then to each column of the result.
The extraction of a texture element and uncovering of a figure buried in a textured image proceed in the same
manner as with the square cases above:
1.
2.
3.
4.
5.
Apply xhel (or xcog) to the input image
Apply texcorrel to the image to determine its periodicity in both dimensions
Apply xhel (or xcog) to a subimage equal to one period in both dimensions to get the texture element
Using the results of steps 2-3, use textile to create a new image the same size as the input image
Display the result of input_image ≠ new_image to reveal the hidden figure
The Texture sub-folder contains a program, xdemo, that illustrates this process and allows for experimentation with
both square and rectangular images and texture elements.
Discussion
With just the resources of the Toolkit, the utility of the Langlet transforms and other operations for texture analysis
is restricted to the kind of well-behaved, toy problem exemplified by the examples in this paper. A real-world
challenge is to invent functions that are still in the Langletian spirit but that can handle a binary image like Fig. 12,
which was made from a photograph of an actual patch of fabric woven in the herringbone pattern. The current
texcorrel function is unable to determine the horizontal periodicity of this patch even though to the eye it is
obvious that the pattern is repeated four times across the image.
Fig. 12 Binary image of herringbone weave fabric
One could take a conventional image processing approach to the analysis of Fig. 12; however, to do so would be to
completely abandon Langlet, who insisted on using only operations in the boolean field that have exact inverses,
plus a bit of integer arithmetic for counting and indexed selection.2 Transforms like the FFT are forbidden because
they operate on floating-point data and return floating-point results, and thus do not generally have exact inverses.
The motivation for at least trying to stay within the Langlet framework is the utter simplicity of its key operations. In
any programming language that has arrays as primitive objects, the Helical and Cognitive transforms can be
implemented in just two or three short lines of code. It should be noted that Langlet himself was never able to make
his transforms do the same work as the FFT. He believed that they could, but one will search his published papers in
vain for any confirming evidence.
Concluding Notes on the Toolkit tex Functions
Although this paper has focused exclusively on the Helical transform, the Cognitive transform will do just as well
for all the image processing shown here. Consequently, some of the tex functions have an fn parameter that allows
the programmer to select which transform will be used. While the results obtained with the Helical transform are not
in general identical to those obtained with the Cognitive transform, the results are so closely similar that when
presented as images they are visually indistinguishable.
The tex functions as currently implemented are fairly sensitive to the particular values of some of their arguments.
The pattern-matching parameter, tol, can be set as low as 0.8 (i.e., at least an 80% pixel match between patterns is
considered satisfactory). The noise parameter can usually be set as high as 0.15 (i.e., about 15% of the pixels in an
image are corrupted). Finally, the density parameter, which determines how many 1’s on average are in each
texture element, generally has to be greater than 0.3 and less than 0.7. Values outside these limits will usually give
disappointing results, or worse, execution errors.
Demos and Experiments
The Texture sub-folder of the Toolkit contains several short Matlab programs, which can be run as-is or modified to
allow experimentation with the different capabilities of the texture processing functions (make sure to put the
Texture and Image sub-folders on the Matlab path). Included are programs to generate each of the figures in the
paper (programs figure1-figure11). The program xdemo allows the user to vary the different texture
processing parameters and to observe the results. The Image sub-folder contains several .gif files which can be used
for experiments. Other binary images may of course be used., The best results are obtained if the images are fairly
thin line drawings. Solid figures generally cannot be concealed within a textured background.
References
[1] Stuart Smith. Reflections on Langlet’s APL Theory of Human Vision. www.cs.uml.edu/~stu
[2] Gérard Langlet. Towards the Ultimate APL-TOE. ACM SIGAPL Quote Quad, 23:1, July 1992.
[3] Michael Zaus. Crisp and Soft Computing with Hypercubical Calculus: New Approaches to Modeling in
Cognitive Science and Technology with Parity Logic, Fuzzy Logic, and Evolutionary Computing: Volume 27 of
Studies in Fuzziness and Soft Computing. Physica-Verlag HD, 1999.
2
The basics of Langlet’s computational system are shown in the Appendix.
Appendix
Langlet’s system of computation operates almost entirely in the boolean field, which consists of the values {0,1},
with exclusive-or (  ) as "addition" and logical-and (∧) as "multiplication." Exclusive-or is extended element-wise
to operate on pairs of vectors of the same length, that is:
(1)
xor( X , Y )  x1  y1 , x2  y2 ,..., xn  yn
Extended exclusive-or and two additional operations together constitute what Zaus [5] calls “generalized” exclusiveor. The additional operations are binary vector integral (bvi), which is defined as
(2)
bvi( X )  x1 , ( x1  x2 ),..., ( x1  x2  ...  xn )
and binary scalar integral (bsi), which is defined as
bsi ( X )  x1  x2  ...  xn
(3)
As can be seen, the final term of the bvi of a given vector is the bsi of that vector. bvi implements parity integration,
which is the core of Langlet’s system. All three generalized exclusive-or operations can also be performed with
addition modulo 2.
A fourth fundamental operation, binary vector differential (bvd), is the inverse of bvi:
bvd (bvi( X ))  X
(4)
It is worth noting that bvi is the same process used for graycode-to-binary conversion, while bvd is the same process
used for its inverse, binary-to-graycode conversion. bvd is defined as
bvd ( X )  xor( shiftr ( X ), X )
(5)
where shiftr shifts its vector argument one position to the right (the shift is end-off, with zero fill on the left).
The basic versions of the Helical and Cognitive transforms of a boolean vector of length n, where n is a power of
two, are defined on an n×n square matrix M. The first row of M is the bvi of the vector to be transformed, and each
subsequent row is the bvi of the preceding row. The last row is the original vector. The Helical transform of the
vector is the main anti-diagonal of M read from lower left to upper right. The Cognitive transform of the vector is
the last column read from bottom to top. There are several other ways to compute the transforms that are much more
economical in terms of computation time and memory utilization. Functions using other algorithms are included in
the Toolkit.
Download