0% found this document useful (0 votes)
38 views

One-Dimensional Vector Based Pattern

ONE-DIMENSIONAL VECTOR BASED PATTERN MATCHING
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

One-Dimensional Vector Based Pattern

ONE-DIMENSIONAL VECTOR BASED PATTERN MATCHING
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

DOI:10.5121/ijcsit.2014.6404 47


ONE-DIMENSIONAL VECTOR BASED PATTERN
MATCHING

Y. M. Fouda
a,b

a
College of Computer Science and Information Technology, King Faisal University, P.O.
Box 400, Al-Ahsa 31982, Kingdom of Saudi Arabia.
b
Mathematics Department, Faculty of Science, Mansoura University, Mansoura 35516,
Egypt.

ABSTRACT

Template matching is a basic method in image analysis to extract useful information from images. In this
paper, we suggest a new method for pattern matching. Our method transform the template image from two
dimensional image into one dimensional vector. Also all sub-windows (same size of template) in the
reference image will transform into one dimensional vectors. The three similarity measures SAD, SSD, and
Euclidean are used to compute the likeness between template and all sub-windows in the reference image
to find the best match. The experimental results show the superior performance of the proposed method
over the conventional methods on various template of different sizes.

KEY WORDS

Image analysis, pattern matching, likeness functions, vector sum.

1. INTRODUCTION

Pattern matching is an important technique in pattern recognition and image processing. It is used
in many applications related to signal processing and machine vision such as object tracking,
stereo matching, video compression, image retrieval and image registration. Template matching
tries to answer one of the most basic questions about image: Is there a certain object in that
image? If so, where? The template is a description of that object, and is used to search the image
by computing a difference measure between the template and all possible portions of the image
that could match the template: if any of these produces a small difference, then it is viewed as
possible occurrence of the object[1].

Various difference measures have different mathematical properties, and different computational
properties had been used to find the best match. The most popular similarity measures are the
sumof absolute differences (SAD), the sumof squared difference (SSD), and the normalized
cross correlation (NCC). Because of SAD and SSD are computationally fast and algorithms are
available which make the template search process even faster, many applications of gray-level
image matching use SAD or SSD measures to determine the best match. However, these measure
are sensitive to outliers and is not robust to variations in the template, such as those that occur at
occluding boundaries in the image. However, the NCC measure is more accurate but it is
computationally slow. It is more robust than SAD and SSD under uniformillumination changes,
International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

48

so the NCC measure has been widely used in object recognition and industrial inspection such as
in [2] and [3]. An empirical study of five template matching algorithms in the presence of various
image distortions has found that NCC provides the best performance in all image categories [4].

Many improvements were occurred on SAD and NCC algorithms to get a better complexity.
Mahmood and Khan [5] proposed a partial computation elimination technique in which at a
particular search location, computations are prematurely terminated as soon as it is found that this
location cannot compete already known best-match location. They showed that partial
elimination technique may be applied to correlation coefficient by using a monotonic formulation
and proposed a basic mode for small template size and an extended mode for medium and larger
template. Chen et al. [6] proposed a fast block matching algorithm based on the winner-update
strategy, which can significantly reduce the computation and guarantee to find the globally
optimal solution. In their algorithm, only the current winner location with a minimal accumulated
distortion is considered for updating the accumulated distortion. This updating process is repeated
until the winner has gone through all levels in the pyramids that are constructed fromthe template
and all the candidate windows for the distortion calculation.

Wei and Lai [7] proposed a fast pattern matching algorithmbased on NCC criterion by combing
adaptive multilevel partition with the winner update scheme to achieve very efficient search. This
winner update scheme is applied in conjunction with an upper bound for the cross correlation
derived from Cauchy-Schwarz inequality. To apply the winner update scheme in an efficient way,
they partition the summation of cross correlation into different levels with the partition order
determined by the gradient energies of the partitioned regions in the template. Thus, this winner
update scheme in conjunction with the upper bound for NCC can be employed to skip
unnecessary calculation. Alsaade and Fouda [8] used Cellular Automata with Rule 170 (CA-
R170) on the images after converting it into binary images. Your technique based on eliminating
some of the undesirable area in the binary reference images and their corresponding binary
template images. Essannouni et. al. [9] proposed a frequency algorithm to speed up the process of
SAD matching using Fast Fourier transforms (FFT). They introduced an approach to approximate
the SAD metric by cosine series which can be expressed in correlation terms. These latter can be
computed using FFT algorithms. Alsaade and Fouda [10] proposed a matching algorithmbased
on SAD as a measure of similarity and pyramid structure. They applied the pyramid concept to
obtain a number of levels of original and template images. Then the SAD measure is applied for
each level of image frombottomto up to obtain the correct match in the original image.

In this paper, we propose an efficient pattern search algorithmbased on Dimension-Reduction
approach for images. Dimension-Reduction technique is applied for the template image and all
corresponding sub-windows in the reference image. In our approach Dimensions-Reduction
technique based on converting the template and all its corresponding sub-windows in the
reference from2-D into 1-D. The sumof square difference measure was used as a similarity
measure to get the template in the reference. The rest of the paper is organized as follows: the
proposed algorithm and its complexity analysis is described in section II. Simulation and
comparison results for NCC and SAD standards are reported in section III. Then we state
conclusions in section IV.





International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

49

2 . THE MAIN CONTRIBUTION

In this section we introduce description of the proposed method followed by its complexity
analysis compared with other four methods.

2.1 The proposed method

Our method has been motivated by a need to develop an efficient matching technique so that the
detection of objects in a reference image can be effective and fast. The proposed matching
algorithm involves three phases. Phase I reduce the amount of data analyzed by transforming 2-D
images (template image and sub-windows which has the same size with template in the reference
image) into 1-D vector information. This can be done by adding all intensity values for each
column in 2-D image see Eq. (1), so we get 1-D vector information. This vector information will
be used in the matching process instead of the 2-D image. This transforming reduce the amount
of image frommn to n. Subsequently, this allows the search to be performed with fewer data,
while still taking all pixel intensity values into account. Phase II measure the likeness between
template image and all possible sub-windows in the reference image. The Euclidean distance or
sumof absolute difference or sumof square difference can be used as a similarity measure
between 1-D template and all 1-D converted sub-window in the reference. Phase III the decision
will be taken based on the similarity values. The sub-window in the reference with minimum
similarity value will be the best match for template in the reference.

The basic idea of the proposed template matching depending on converting 2-D template image
into 1-D and also the corresponding windows in the reference image over which the template lies.
To illustrate the idea suppose that we have a reference image S of size pq and template image T
of size m n where m < p and n < q. The problem is to find the best match of template T from the
reference image S with minimumdistortion.

First the template image T(i,j) converted to 1-D vector NT by the equation


|
.
|

\
|
=

= = = =
m
i
m
i
m
i
m
i
n i T i T i T i T i NT
1 1 1 1
) , ( , , ) 3 , ( , ) 2 , ( , ) 1 , ( ) ( (1)
where T(i,j) is the pixel value at location (i,j) of the template image.


Secondly, for each pixel (i,j) in the reference image S, 1 i <p-m and 1 j <q-n, we determine a
window W(i,j) of size mn and all these windows converted into 1-D vector NW by the equation

|
.
|

\
|
+ + + =

+
=
+
=
+
=
+
=
1 1 1 1
) 1 , ( , , ) 2 , ( , ) 1 , ( , ) , ( ) , (
i m
i k
i m
i k
i m
i k
i m
i k
j n k W j k W j k W j k W j i NW (2)
where W(k,j) is the pixel value at location (k,j) of the reference image.

Thirdly, the likeness between template image and each corresponding window in the reference
are measured by sumof square difference distance between NT and NW. All these distances
compute and store in new storage C(i,j) where
International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

50

2
1
1
2
1
1
2
1
1
) , ( ) 1 , ( ) 2 , ( ) 1 , ( ) 1 , ( ) , ( ) , (
|
.
|

\
|
+ +
|
.
|

\
|
+ +
|
.
|

\
|
=

+
= =
+
= =
+
= =
i m
i k
m
i
i m
i k
m
i
i m
i k
m
i
n i T j n k W i T j k W i T j k W j i C

where 1 i < p-m and 1 j < q-n. (3)
If the positive ordered pair ) , ( j i be such that ) , ( j i C is the lowest obtained distance, then return
) , ( j i as the left upper corner of best template match in our proposed method. Fig. (1) show the
concept of the proposed method.


Fig. 1: Illustration of the proposed. The template image is converted into 1-D and also the corresponding
windows in the reference, SSD is calculated at every possible location in the reference. The (i,j) location of
matrix C with the minimum value is considered as the location of best match.

International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

51

2.2 Complexity analysis

In order to evaluate the efficiency of the proposed algorithm, we discuss the complexity of our
algorithmcompared with four important methods of template matching NCC, SAD, NCCP, and
SADP. For NCC algorithm, the cross correlation coefficient between template image T of size
nn pixels and an nn pixels block in reference image S of size pq is given by:
( )( )
( ) ( )

= = = =
= =
+ +
+ +
=
n
x
n
y
n
x
n
y
n
x
n
y
T y x T j i S y j x i S
T y x T j i S y j x i S
j i
1 1 1 1
2 2
1 1
) , ( ) , ( ) , (
) , ( ) , ( ) , (
) , ( , 1i<(p-n), 1j<(q-n)
(4)
where

= = = =
= + +

=
n
x
n
y
n
x
n
y
y x T
n n
T and y j x i S
n n
j i S
1 1 1 1
) , (
1
) , (
1
) , (
Direct computation of (i,j) require nn=n
2
(addition/ multiplication) operations at each point
(i,j) in the reference image where 1 i<(p-n), 1 j<(q-n) . Then the operations in Eq. (4) is
proportional to n
2
(p-n+1)(q-n+1). So the computational cost of NCC is (n
2
(p-n+1)(q-n+1))
which is very time consuming.

For SAD method the sum of absolute difference between the template T of size nn pixels and
blocks of sizes nn pixels in the reference image S is given by:

= =
+ + =
n
x
n
y
y x T y j x i S j i SAD
1 1
) , ( ) , ( ) , ( (5)
The computation of SAD(i,j) requires a number of operations proportional to the template area
(nn). These operations are computed for each (i,j) in the reference image where 1 i<(p-n), 1
j<(q-n). Then the computational cost for SAD method is (n
2
(p-n+1)(q-n+1)) the same in NCC
algorithmbut the SAD method is faster than NCC method because the number of operations in
SAD is less than number of operations in NCC for each position (i,j) in the reference image about
seventy percentage.

The two methods NCCP and SADP can achieve the same estimation accuracy as NCC and SAD
while needing much less computation requirement than theses two methods. When the pyramid is
applied for NCC and SAD, a sequence of compressed template and reference images are created
using:
( ) ) 1 2 , 1 2 ( ) 1 2 , 2 ( ) 2 , 1 2 ( ) 2 , 2 (
4
1
) , (
1 1 1 1
+ + + + + + + =

y x I y x I y x I y x I y x I
k k k k k
(6)
where I
k
(x,y) is the intensity value for the image in the level k. The search is conduct using NCC
or SAD (Eq. (4) or (5)) with the most compressed template and reference image. The resulting
pixel location provides a coarse location of the template pattern in the next lower level of the
International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

52

reference image. Therefore, instead of performing a complete search in the next level, one require
to only search a close neighborhood of the area computed fromthe previous search. This
sequence is iterated until the search in the reference image is searched.

In the pyramid concept the complexity of the algorithm depend on the position of template in the
reference. If the template coordinates is far fromthe x-direction and y-direction then applying
pyramid outperformthe original method. But, if the x-coordinate for template in reference is
close to x-axis and/or y-coordinate for template in reference is close y-axis the original method
outperformthe pyramid concept.

To overcome the problemin pyramid concept and the computational intensive in NCC and SAD
we introduced our approach. The computation in Eq.(3) require a number of operations
proportional to the length n of the converted vector from2-D into 1-D. These operations are
computed for each position (i,j) in the reference image where 1 i<(p-n), 1 j<(q-n). Then the
computational cost of the proposed method is (n(p-n+1)(q-n+1)) and this justify why the
proposed method outperformthe others.

3 EXPERIMENTAL RESULTS

To measure the efficiency the proposed method was implemented. For the comparing purpose,
we also implemented four different algorithms the full-search NCC algorithm, NCC pyramid
(NCCP) algorithm, sumof absolute difference (SAD) algorithm, and SAD pyramid (SADP)
algorithm. Theses algorithms were implemented in a Matlab 7.0 on a Laptop with an Intel
Core2 Duo CPU T7500 @ 2.20 GHz and 1.99 GB RAM. Two types of images are used for the
testing purpose color images and gray scale images. Greens image of size 300500 is a
representative for color case see fig. 2(a). Lifting-body of size 512512 is a representative for
gray scale case see Fig. 3(a). In our experiments we cropped the templates fromthe reference (see
Fig. 2(b) and Fig. 3(b)) so we know in advance the correct position for template in the reference.
The size of these templates varying from2525 to 200200 pixels.


(a)
International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

53


(b)
Fig. 2. (a) Original greens image and (b) The cropped template images form the original with sizes varying
from 25x25 to 150x200 pixels.


(a)
International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

54


(b)
Fig. 3. (a) Original Lifting-body image and (b) The cropped template images form the original with sizes
varying from 25x25 to 200x200 pixels.

In the clean data, the proposed and compared algorithms are guaranteed to find the correct match
fromthe reference image, so we only focus on the comparison of search time required for these
algorithms. In the proposed method the similarity between template and sub-windows in the
reference image can be measure using more than one similarity function. For example the
Euclidean distance or sumof absolute difference or sumof square difference can be used. The
mathematical formula for sumof square difference are used in our method (see Eq. (3)). To apply
the Euclidean distance and sum of absolute difference functions in our method their mathematical
formula is given by the following equations respectively.

2
1
1
2
1
1
2
1
1
) , ( ) 1 , ( ) 2 , ( ) 1 , ( ) 1 , ( ) , ( ) , (
|
.
|

\
|
+ +
|
.
|

\
|
+ +
|
.
|

\
|
=

+
= =
+
= =
+
= =
i m
i k
m
i
i m
i k
m
i
i m
i k
m
i
n i T j n k W i T j k W i T j k W j i C
(7)
and

+
= =
+
= =
+
= =
+ + + + =
1
1
1
1
1
1
) , ( ) 1 , ( ) 2 , ( ) 1 , ( ) 1 , ( ) , ( ) , (
i m
i k
m
i
i m
i k
m
i
i m
i k
m
i
n i T j n k W i T j k W i T j k W j i C
(8)
Figs. 4 and 5 compare between the three similarity functions for the images greens and lifting-
body, respectively. In this comparing we taken five template with different sizes from each
reference and computing the time confused by each similarity function in our proposed method.
As can be seen fromFig. 4, SSD function outperforms Euclidean and SAD functions but the
International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

55

required time of the three functions is almost the same at template of sizes 2525 and 150150.
Also, fromFig. 5, we can see that SSD function outperformEuclidean and SAD functions but the
required time for the three functions is almost the same at template of sizes 2525 and 200200.
Finally, from these two figures, we can see that for the two kind of images the SSD functions is
the best because the number of operations of SSD is less than the number of operations in SAD
and Euclidean (see Eqs. (3), (7) and (8)).

Fig. 4. Comparisons between the three similarity functions on greens image using different size of template


Fig. 5. Comparisons between the three similarity functions on lifting-body image using different size of
template

0
5
10
15
20
25
30
35
40
45
50
25x25 50x50 100x100 150x150 150x200
Eculdiean
SSD
SAD
0
20
40
60
80
100
120
25x25 50x50 100x100150x150200x200
t
i
m
e

(
s
e
c
s
)
template size
Eculdiean
SSD
SAD
International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

56

The execution time required for the proposed and compared algorithms is shown in Tables I and
II. These Tables shows the performance comparison of the above mentioned algorithms using
color image of size 300500 and gray scale image of size 512512 respectively. For each
reference image the templates are cropped with sizes from2525 to 200200. Fromthese Tables
we see that the times in Table I is less than its corresponding times in Table II because the size of
reference image in Tables I and II are 150000 and 262141 pixels respectively. In Table I the
running time for NCCP and SADP algorithms for 150150 template is greater than 200200
template although the converse must be satisfied. This result because the 150150 template is
very close the y-direction in greens image. NCCP and SADP give a better results than NCC and
SAD when the template is far fromthe x-direction and y-direction in the reference image.


Table I Execution time by seconds of applying NCC, NCCP, SAD, SADP, and proposed
method with five templates shown in fig. 2(b) and the reference image show in fig. 2(a).
Template
size
Algorithm
NCC NCCP SAD SADP Proposed
2525 18.95 8.97 5.12 3.03 1.06
5050 56.58 42.25 16.66 14.19 7.7
100100 158.28 75.16 45.87 24.78 23.17
150150 223.52 135.42 68.56 46.05 36.88
150200 255.05 121.17 78.92 41.52 38.92


Table II Execution time by seconds of applying NCC, NCCP, SAD, SADP, and proposed
method with five templates shown in fig. 3(b) and the reference image show in fig. 3(a).

Template
size
Algorithm
NCC NCCP SAD SADP Proposed
2525 35.52 21.26 10.31 6.81 2.26
5050 120.26 49.86 34.4 17.38 15.23
100100 339.05 213.23 104.19 75.12 50.39
150150 573.36 290.14 198.52 103.45 94.86
200200 779.91 349.09 241.12 129.27 106.6

Fromtable I, it is clarified that the processing time for the proposed is less than that for NCC,
NCCP, SAD, and SADP. For example, using the 5050 template, the processing time for the
proposed was 7.7 s, however, NCC, NCCP, SAD, and SADP matching required 56.58, 42.25,
16.66, and 14.19 s respectively. This means that the proposed give an improvement at least about
50%. Also from table II the required time of the proposed is better than another all algorithms for
all templates. Since the complexity of the proposed is more efficient than the other methods. Figs.
6 and 7 shows the performance of the proposed algorithm compared with other four algorithms
using greens image (color case) and lifting-body (gray scale case) respectively. It is clear that the
proposed algorithmoutperformthe other in the two cases for all template sizes. In the above
experiments, the correct match position is assumed to be the position where the minimum
similarity distance value is obtained when the entire template is used in the search process.

International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

57


Fig. 6. Performance of the proposed algorithm using greens image


Fig. 7. Performance of the proposed algorithm using lifting-body image

4. CONCLUSION

In this paper, we have proposed a new template matching which can be speed up the computation
of block matching while still guaranteeing the correct match for template in the reference. To
achieve efficient computation, we converted the template and each corresponding block in the
reference from 2-D into 1-D. We have applied the proposed idea to the template matching using
three different similarity measure, and have a reduction in computation time. Two different types
of image (color and gray scale) are used for comparison between proposed algorithmand other
algorithms. The templates are cropped fromthe reference image. The experimental results show
the proposed algorithm is efficient for pattern matching under uniformillumination.


0
50
100
150
200
250
300
25x25 50x50 100x100 150x150 150x200
t
i
m
e

(
s
e
c
s
)
template size
NCC
NCCP
SAD
SADP
Proposed
0
200
400
600
800
1000
25x25 50x50 100x100 150x150 200x200
t
i
m
e

(
s
e
c
s
)
template size
NCC
NCCP
SAD
SADP
Proposed
International Journal of Computer Science & Information Technology (IJCSIT) Vol 6, No 4, August 2014

58

REFERENCES

1. Mikhail, I. A.: Faster image template matching in the sum of the absolute value of differences
measures. IEEE Trans. Image Processing. 10(2), 659-663 (2001)
2. Du-Ming, T., Chien-Ta, L.: Fast normalized cross correlation for detect detection. Pattern
Recognition Letters 24, 2625-2631 (2003)
3. Costa, C. E., Petrou, M.: Automatic registration of ceramic tiles for the propuse of fault detection.
Machine Vision Application 11, 225-230 (2000)
4. Li, R., Zeng, B., Liou, M. L.: A new three-step search algorithm for block motion estimation. IEEE
Trans. Circuits Systems Video Technology, 4(4), 438-442 (1994)
5. Mahmood, A., Khan, S.: Correlation coefficient based fast template matching through partial
elimination. IEEE Trans. Image Processing. 21(4), 2099-2108 (2012)
6. Chen, Y.S., Huang, Y.P., Fuh, C. S.: A fast block matching algorithm based on the winner-update
strategy. IEEE Trans. Image Processing , 10(8), 1212-1222 (2001)
7. Wei, S., Lai, S.: Fast template matching based on normalized cross correlation with adaptive
multilevel winner update. IEEE Trans. Image Processing, 17(11), 2227-2235 (2008)
8. Alsaade, F., Fouda, Y., Khan, A. R.: Efficient cellular automata algorithm for template matching.
Journal of Artificial Intelligence, 5(3), 122-129 (2012)
9. Essannouni, F.,Thami, R.O.H., Aboutajdine, D., Salam, A.: Adjustable SAD matching algorithm
using frequency domain. J Real-Time Image Proc 1(4), 257-265 (2007)
10. Alsaade, F., Fouda Y.: Template matching based on SAD and pyramid. International Journal of
computer science and information security, 10(4), 11-16 (2012).

You might also like