Fast Template Matching System Using VHDL: Richard Tate and James Northern III, Member, IEEE
Fast Template Matching System Using VHDL: Richard Tate and James Northern III, Member, IEEE
Fast Template Matching System Using VHDL: Richard Tate and James Northern III, Member, IEEE
A. Cross-Correlation Comparison
Our matching process uses cross-correlation comparison,
which is the process of the template being matched with each
binary bit in the image. Figure 2 shows a diagram of the
template as it relates to the size of the image.
The correlation can be described mathematically by cross-
correlation function in (eq. 1).
16 16
M x1, y1 = ∑∑ I cx,cyTcx + x1,cy + y1
Figure 3. Overlay of template and image search image
cx cy
(eq. 1)
The multiplexers are used to control the data flow from the
output of the exclusive NOR gates. The multiplexer allows for
expandability and parallel matching to be achieved. The 32
outputs from the exclusive NOR gate arrays are connected to
the multiplexer. The selector input is controlled by the
template input which is sixteen bits. The multiplexer outputs a
16 bit string that represents the hits and misses for the
comparison match. The binary string “1011011111011111” is
an example of the output from the multiplexers. This output is
equal to 13 hits and 3 misses. In section IV we explain how
this allows for mid-simulation adjustment to the 4x4 template
array.
B. Computation of Hit Rate and Threshold
Once the matching is completed, the output matching is set1 set2 set3 set4
calculated for hit rate. The hit rate module contains half Figure 4. Four sets of 4x4 templates stored in the Library Module
adders connected together adding each of the sixteen bits
together and outputting a five digit representation of the total Using Figure 4, each set has template that have at least two
number of hits. Five digits are used because the “00000” is binary bits in common. The threshold here would be set to
still needed to represent the value of zero. have a hit of count of 14 or greater. The 14 or greater
The output value is then compared to the stored threshold threshold eliminates the Regeneration of templates that do not
value for comparison. If the threshold value is met, the value exist in the set of templates. If 16 are reached then no
of the hit count, the column, the row, and an address is passed template generating is needed. Each set represents a different
to the output RAM. A new address is then generated. If the template matching array.
threshold is not met, the threshold will send a ‘Z’ signal to the The process of template creating is done using the output of
RAM. Once the image switches back to read or to the set of the multiplexer and the threshold. Using the above example if
templates being processed, the threshold address value returns the threshold is passed and using set 1, with the first template
to zero. as the initial run template, a possible output of the multiplexer
is “1111110111111101”. The outputted value is compared
III. CREATING THE TEMPLATE with the current template and the values that correspond with
the 1’s remain the same and the values that correspond with
Using the output of the multiplexers and jot count we can
the 0’s are inverted. Using the first template in binary form
generate a best fit template for a certain location within the
image that achieves a predetermine threshold. The purpose of “0000000001100010” and the outputted value form the
this is to create a template that correctly matches the position multiplexer “1111110111111101” we can create a new
in the image that is being cross-correlation matched at that template:
moment. Although this template would provide a perfect
Template
match for that location in the image, it must still be able to
0000000001100010
compare to templates within the predetermine set of available
templates. The number of template that is regenerated must
Output of the matching circuit
also be limited so that bottleneck is not created within the
1111110111111101
system by matching newly created templates that would not
provide for better matches.
New template
A. Threshold 0000001001100000
To reduce the amount of templates that are created we use a
threshold to determine when a template should be generated.
The threshold is based on difference between bits within a set
of templates. The set of templates are made up of templates
that have bits in common. The sets are stored in a Library. For
this paper we used templates that have two bit difference
between each template in the set. Using the two bit difference
we can reduce the amount of templates that the system creates,
hence reducing the number of useless searches performed. It
should also be noted that the reduction is only presence when
there is an image that causes the Template Regeneration
This new template is then matched against the template in
Module to be activated. The threshold is based on the
the set. If a correct match is found then at that position a
maximum difference in the bits in the Library Module. Using
100% match ratio is calculated. If a template is found that has
the earlier example with a pixel change of two, the threshold
a higher hit rate than the current template, that template is
for that set of pixels is equal to fourteen or greater, which
marked to have the highest hit rate value for that position in
means if the output of the hit count is greater than or equal
the image.
fourteen a template is generated for matching.
IV. ATR SYSTEM TESTING AND EVALUATION
This section will describe the experimental simulation of
the Template Regeneration Module. The simulation tool used
for evaluation is Modelsim XE III. The clock is set to 200
MHZ. The testbench was creating in Xilinx ISE testbench
waveform editor. The circuit utilizes one library module (16
templates) and an image of 16x16 pixels, where one pixel is
equal to one bit. A target was placed to trigger the template
regeneration module. The image was placed at row five,
column four (reading from right to left) or (column 13, row 5
reading from left to right) of the search image, as shown in
Figure 5. The starting template was the first template in set 1.
The templates were processed in the order from top to bottom.
The target image was created to be identical to the second
template in set 2.
Two types of simulations were performed, the first using B. Template generation circuit
the original template matching circuit, and the second with the
For the template generation circuit, the simulation data
template regeneration circuit. This test provided a gauge for
shows that at 34.5 microseconds, the first template matched
performance of the overall circuit. Additional simulations
the target with a threshold of fourteen. It took an additional
were done to change the shape of the trigger image to evaluate
five clock cycles to match the sixth template, which is the best
the performance of the template generation circuit.
match for that particular target. In this example, it shows that
the template regeneration circuit can identify the correct
template 18 times as fast as the original template matching
circuit. The number of searches that the regeneration circuit
would have to process is 73.
# of searches = [((4x16)+4)+5] = 73
# of searches = [((4x16)+4)+(16x16x5)]
# of searches = 1350
Figure 7. Original template matching library
V. CONCLUSION
Template matching is a very important task that must be
performed effectively within an ATR system. The goal of the
design was to create a sub-system within the ATR
environment that could do mid-simulation changes to the
template matching circuit, parallel matching, and template
regeneration during the simulation. In this paper a template
matching system was presented. The system was developed
using Xilinx and simulated in Modelsim XE III. The system
was tested using various conditions to ensure performance.
Analysis of the data shows the system to be effective in
reducing search time to locate a possible target.
ACKNOWLEDGEMENTS
This material is based upon work supported by the
USAF/AFRL at Wright Patterson AFB Sensors Directorate
under Contract No. FA8650-05-D-1912. Any opinions,
findings and conclusions or recommendations expressed in
this material are those of the author(s) and do not necessarily
reflect the view of the USAF/AFRL, Wright Patterson AFB
REFERENCES
[1] Clark F. Olson and Daniel P. Huttenlocher “Automatic Target
Recognition by Matching Oriented Edge Pixels”, IEEE
Transactions on Image Processing, vol. 6, no. 1, January 1997.