# Patent

## Title
Template matching apparatus and method thereof

## Abstract

A template matching apparatus includes a template input unit configured to input the template image; a signal input unit configured to input an image to be matched; a template scaling unit configured to scale the template image; a matching unit configured to match a scaled template image and an input image; a scaling factor determining unit configured to determine a scaling factor of the template image on the basis of a similarity obtained by matching; and a result output unit configured to output a result of matching when matching within a range of a predetermined scaling factor is completed.

## Background
This application is the U.S. national phase of International Application No. PCT/JP2009/054701, filed 2 Mar. 2009, which designated the U.S. and claims priority to JP Application No. 2008-064537, filed 13 Mar. 2008, the entire contents of each of which are hereby incorporated by reference.
TECHNICAL FIELD
The present invention relates to a template matching apparatus configured to match a template with an input signal fast while expanding or reducing the same and a method thereof.
BACKGROUND ART
In the template image matching method disclosed in Hiroshi MURASE, V. V. Vinod, “Fast visual search using focused color matching—active search” Publication of The Institute of Electronic, Information and Communication Engineers, vol. J81-D-II, No. 9, pp. 2035-2042, September 1998 (Non-Patent Document 1), the active search method is proposed which is able to search a template fast by omitting matching transactions within the regions having the similarity which does not reach a predetermined threshold value θ. The regions are derived from an upper limit of the similarity of a periphery of the template image based on a feature such that, a similarity of a template image is not changed abruptly even though it is slightly moved.
Accordingly, the active search method achieves a fast detection of a position of the template image.
DISCLOSURE OF INVENTION
In case of the size of the matching region in the input image is not unknown, it is necessary for existing search methods to search the template image by changing the size of the template image little by little. Therefore the existing methods were not able to achieve fast search about size change.
Accordingly the present invention provides a template matching apparatus which achieves a fast matching even when the size of the template image is changed and a method thereof.
The present invention provides a template matching apparatus including: a signal input unit configured to input an input signal; a matching unit configured to (1) obtain similarities with a template having a predetermined initial size or templates obtained by scaling the templates having the initial size by a given scaling factor in sequence while moving a search position on the input signal, (2) obtain the similarities on the basis of a distribution of an amount of characteristics of the templates and a distribution of an amount of characteristics in a search window on the input signal at respective search positions, and (3) obtain a highest similarity from among the similarities; a limit value calculating unit configured to calculate an upper limit value of expansion or a lower limit value of reduction of the scaling factor of the template from the highest similarity so that the highest similarity obtained when the template is expanded or reduced does not exceed a threshold value; a scaling unit configured to expand or reduce the template on the basis of the scaling factor within the upper limit value of expansion or the lower limit value of reduction; a repeat control unit configured to expand and reduce the template by the scaling unit until the template having the size included in a given range is achieved and repeat searching on the basis of the expanded or reduced template by the matching unit.
The present invention also provides a template matching apparatus including: a signal input unit configured to input an input signal: a first matching unit configured to (1) obtain similarities with a template having a predetermined initial size or templates obtained by scaling the templates having the initial size by a scaling factor within a given scaling range in sequence while moving a search position on the input signal, (2) obtain the similarities on the basis of a distribution of an amount of characteristics of the templates and a distribution of an amount of characteristics in a search window on the input signal at respective search positions, and (3) obtain a highest similarity from among the similarities; an estimating unit configured to estimate an estimated highest similarity for the input signal when the template is expanded or reduced on the basis of the highest similarity; a first limit value calculating unit configured to calculate an upper limit value and a lower limit value of the scaling factor of the template from the estimated highest similarity so that a highest similarity when the template is expanded or reduced does not exceed a threshold value; a scaling unit configured to scale the template by the scaling factor within a scaling range determined by the upper limit value and the lower limit value; a second matching unit configured to (1) obtain the similarity of the scaled template while moving a search position on the input signal, (2) obtain similarities on the basis of a distribution of the amount of characteristic on the template and a distribution of the amount of characteristic in the search window on the input signal at the respective search positions, and (3) obtain a highest similarity among the similarities; a second limit value calculating unit configured to calculate a scaling range including an upper limit value of expansion or a lower limit value of reduction of the scaling factor of the template from the highest similarity so that the highest similarity when the template is expanded or reduced does not exceed the threshold value; a backtrack unit configured to change the scaling factor used in the matching unit when the scaling range obtained by the second limit value calculating unit and the scaling range whereby a size of the template used by the first matching unit for searching is determined are not overlapped; and a renewing unit configured to control the estimating unit to use the highest similarity from the second matching unit instead of the highest similarity from the first matching unit when the scaling range obtained by the second scaling ratio calculating unit and the scaling range whereby the size of the template used by the first matching unit for searching is determined are overlapped; and a repeat control unit configured to expand or reduce the template by the scaling unit until the size of the template reaches a given range and repeat the search by the template expanded or reduced by the first matching unit and the second matching unit.
According to the embodiments of the present invention, fast search is achieved by reducing the number of times of the scaling of the template without causing missing detections.



BRIEF DESCRIPTION OF THE DRAWINGS
FIG. 1 is a block diagram showing a configuration of a template matching apparatus according to a first embodiment.
FIG. 2 is a flowchart showing an operation of the first embodiment.
FIG. 3 is an explanatory drawing showing an outline of an image matching according to the first embodiment.
FIG. 4 is a drawing for explaining a method of calculating an upper limit of a scaling factor when expanding a template according to the first embodiment.
FIG. 5 is a drawing for explaining a method of calculating a lower limit of the scaling factor when reducing the template according to the first embodiment.
FIG. 6 is a drawing for explaining a state of matching while changing a scaling width according to the first embodiment.
FIG. 7 is a drawing for explaining a case where a distribution of histogram characteristics is changed abruptly according to a third modification in the first embodiment.
FIG. 8 is a drawing for explaining a case where the distribution of the histogram characteristics is not changed abruptly according to the third modification in the first embodiment.
FIG. 9 is an explanatory drawing showing an outline of a voice matching according to a second embodiment.
FIG. 10 is a drawing for explaining a method of calculating the upper limit of the scaling factor when expanding the template according to the second embodiment.
FIG. 11 is a drawing for explaining a method of calculating the lower limit of the scaling factor when reducing the template according to the second embodiment.
FIG. 12 is a drawing for explaining a state of matching while changing the scaling width according to the second embodiment.
FIG. 13 shows a result of experiment in which processing speeds in the voice matching according to the second embodiment and the method in the related art are compared.
FIG. 14 is a drawing for explaining a method of calculating the upper limit of the scaling factor when scaling the template according to a fourth embodiment.



BEST MODE FOR CARRYING OUT THE INVENTION
Referring now to the drawings, a template matching apparatus according to embodiments of the present invention will be described.
A template matching apparatus whose search space has two dimension will be described in a first embodiment, a template matching apparatus whose search space has one dimension will be described in a second embodiment, a template matching apparatus whose search space has n dimensions will be described in a third embodiment, a template matching apparatus whose search space has n dimensions and a scaling factor of a template is different from dimension to dimension will be described in a fourth embodiment, and a template matching apparatus which calculates similarities (inverse of distance) by a norm on the basis of an average brightness will be described in a fifth embodiment.
(1 First Embodiment)
Referring now to FIG. 1 to FIG. 6, the template matching apparatus according to the first embodiment of the invention will be described.
In this embodiment, an image matching whose search space has two dimensions will be described as an example. Matching is carried out while expanding or reducing at a scaling factor α of a template image. As a result of matching, a reduction ratio αmax of the template image having the highest similarity and the position thereof (xmax, ymax) will be outputted.
(1-1) Configuration of Template Matching Apparatus
FIG. 1 is a block diagram showing the template matching apparatus.
The template matching apparatus includes a template input unit 100 configured to input the template image, a signal input unit 101 configured to input an image to be matched, a scaling unit 102 configured to scale the template image, a matching unit 103 configured to match the scaled template image and an input image, a limit value calculating unit 104 configured to determine the scaling factor of the template image on the basis of the similarity obtained by a matching, and a result output unit 105 configured to output a result of matching when the matching is completed over an entire range of a predetermined scaling factor.
The template input unit 100 inputs a template image signal and stores the same in a memory.
The signal input unit 101 inputs the image to be matched with the template image and stores the same in the memory.
The scaling unit 102 scales the template image on the basis of the scaling factor which is determined by the limit value calculating unit 104, described later, and stores the same in the memory.
The matching unit 103 matches the template image scaled in the scaling unit and the input image input in the signal input unit and detects a position where the highest similarity is obtained.
The limit value calculating unit 104 calculates at least one of an upper limit or a lower limit which allows scaling of the template on the basis of the similarity detected by the matching unit 103. The limit value calculating unit 104 also serves as a repeat control unit which controls the scaling unit 102 and the matching unit 103 to repeat scaling and matching until the matching is completed over an entire range of a predetermined scaling factor.
The result output unit 105 outputs the scaling factor and the position in the input image at which the highest similarity is obtained.
The template matching apparatus can also be realized by using a multi-purpose computer apparatus as a basic hardware. In other words, the template input unit 100, the signal input unit 101, the scaling unit 102, the matching unit 103, the limit value calculating unit 104 and the result output unit 105 may be realized by causing a processor mounted on the computer apparatus to execute a program. At this time, the template matching apparatus may be realized by installing the program in the computer apparatus in advance, or may be realized by storing the same in a storage medium such as a CD-ROM or by distributing the program via a network and installing the program in the computer apparatus as needed. Also, B and C are realized by using storage medium such as a memory or a hard disk built in or externally connected to the computer apparatus, CD-R, CD-RW, DVD-RAM, or DVD-R as appropriate.
(1-2) Expansion
Referring now to FIG. 2 and FIG. 3, an operation of the template matching apparatus will be described. FIG. 2 is a flowchart showing the operation of the template matching apparatus. FIG. 3 is an explanatory drawing showing an outline of the image matching.
In this embodiment, the matching may be proceeded while expanding the template, or the matching may be proceeded while reducing the same. A case of matching while expanding the scaling factor of the template from one time to βlim times (where βlim>1) will be described below.
In Step 200, the scaling factor α of the limit value calculating unit 104 is initialized to 1.
A scaling width β which indicates a ratio between the size of the input template and the size of the current template is initialized to 1.
A highest similarity Smax of the result output unit 105 is initialized to 0.
A search position (x, y) is initialized to (−1, −1), which is out of range of the search space. The position of the image may be indicated by coordinates from an original point (0, 0) to maximum numbers of pixels in vertical and horizontal directions. When scanning the image, scanning proceeds from the position of the original point (0, 0) in the vertical and horizontal directions in sequence.
The template image is inputted by the template input unit 100 and is stored in the memory in advance.
The image to be matched is also inputted by the signal input unit 101 and stored in the memory in advance.
A threshold value θ is set. In this invention, positions whose similarities are lower than θ are not determined.
In Step 201, the scaling unit 102 stores the template image scaled at the scaling factor α in the memory.
In Step 202, the matching unit 103 matches the scaled template and the input image, and detects the search position (x, y) where the highest similarity is obtained and a similarity S thereof.
In this embodiment, normalized histogram intersection is employed as the similarity. The method of matching may be any method as long as it can detect the position on the input image where the highest similarity is obtained. For example, the method by Murase in Non-Patent Document 1, or a method of searching all the searching point may be employed for detection.
The normalized histogram intersection is obtained by an expression (1) where the signs hw and ht represent a search window on the input image and a m-dimensional vector which represents a histogram as the distribution of the template, respectively, and the signs hwi and hti represent the search window on the input image and an ith histogram element of the template, respectively.




  
    
      
        
          s
          ⁡
          
            (
            
              
                h
                w
              
              ,
              
                h
                t
              
            
            )
          
        
        =
        
          
            ∑
            
              i
              =
              1
            
            m
          
          ⁢
          
            min
            ⁡
            
              (
              
                
                  h
                  wi
                
                ,
                
                  h
                  ti
                
              
              )
            
          
        
      
    
    
      
        (
        1
        )
      
    
  




In Step 203, the result output unit 105 inputs the scaling factor α, a position (x, y) where the highest similarity is obtained, and the similarity S thereof. When the relation Smax>S is established, it is renewed to Smax=S.
In Step 204, the limit value calculating unit 104 calculates an upper limit value αupper of the scaling factor on the basis of maximum value S of the similarity detected by matching and the threshold value θ. A method of calculating the value αupper will be described later. The scaling factor α is set to a range which does not exceed the upper limit value αupper. When the value αupper falls short of a predetermined minimum value αmin of the scaling factor, α is set as α=αmin.
In Step 205, the limit value calculating unit 104 renews the scaling width with β=βXα.
In Step 206, the limit value calculating unit 104 controls such that the procedure goes back to Step 201 and the processes from Step 201 to Step 205 are repeated if the scaling width is β≧βlim.
In Step 207, the result output unit 105 outputs the highest similarity Smax and the search position (x, y) thereof and end the process.
(1-3) Method of Calculating Upper Limit of Scaling Factor in Expansion
Referring now to FIG. 4 and FIG. 6, a method of calculating the upper limit of the scaling factor in expansion of the template will be described.
FIG. 4 is a drawing for explaining a method of calculating the upper limit of the scaling factor when expanding the template. An upper side of FIG. 4 shows a state of matching a template image having an original size and an input image, and a lower side of FIG. 4 shows a state of matching an expanded template image and the input image. FIG. 6 is a drawing for explaining the state of matching while changing the scaling width β.
The sign S represents the similarity in the template of the original size, where 0≦S≦1 is satisfied.
A sign Sb1 represents a highest similarity in a range of an original template after the expansion, where 0≦Sb1≦1 is satisfied.
A sign Sb2 is the highest similarity in an off-template region on the template after the expansion, where 0≦Sb2≦1 is satisfied.
A sign α represents the scaling factor (an expansion ratio) of one side of the template, where 1<α is satisfied.
A sign R1 represents the search window as a matched region on the original template.
A sign R2 represents the search window on the expanded template.
In this manner, when matching is performed with the template magnified by α, the number of matched pixels on the expanded template is increased to α2 times as shown by a hatched region on the lower left portion of FIG. 4.
When calculating the similarities on the basis of the normalized histogram intersection, when it is assumed that there are sufficient number of pixels which have a potential to match on the input image, the upper limit of the similarity after the expansion in a search window R1 with the original template is Sb1=S as shown by a hatched region shown in the lower right in FIG. 4.
In contrast, when it is assumed that an entire part of an off-R1 region in a search window R2 on the expanded template contributes increase in similarity, the highest similarity in the off-R1 region is Sb2=1−1/α2. Therefore, the upper limit of similarities after the expansion is expressed by a following expression (2).

Sb=Sb1+Sb2=S+1−1/α2  (2)

When solving the expression to obtain α2 on the basis of Sb<θ,

−1/α2<θ−1−S 

is obtained. The sign θ is a threshold value given in advance, and 0≦θ≦1. Since θ−1−S<0 is always satisfied,

α2<1/(1+S−θ)

is obtained. The expansion is considered in this case, α2>1, that is, S<θ should be satisfied.

Therefore, the range of α2 which satisfies Sb<θ may be expressed by a following expression (3).

1<α2<1/(1+S−θ), where S>θ  (3)

(1-4) Reduction

In the description given above, the case where the template is expanded has been described. However, fast matching is also achieved by reducing the template. In this case, only Step 204 and Step 206 are different. A case of matching while reducing the template from one time to αlower times will be described only about the difference as Step 204′ and Step 206′.
In Step 204′, the limit value calculating unit 104 calculates a lower limit value αlower of the scaling factor on the basis of the maximum value S of the similarity detected by matching. A method of calculating αlower will be described later. The scaling factor α is set to a range which does not fall short of the lower limit value αlower. When the value αupper is smaller than the predetermined minimum value αmin of the scaling factor, α is set as α=αmin.
In Step 206′, if the scaling width is β≧βlim, the procedure goes back to Step 201, and the processes from Step 201 to Step 205 are repeated. Otherwise, the procedure goes to Step 207.
(1-5) Method of Calculating Lower Limit of Scaling Factor in Reduction
Referring now to FIG. 5, a method of calculating a lower limit of the scaling factor in reduction of the template will be described.
FIG. 5 is a drawing for explaining a method of calculating the lower limit of the scaling factor when reducing the template. An upper side of FIG. 5 shows a state of matching the template image having the original size and an input image, and a lower side of FIG. 5 shows a state of matching a reduced template image and the input image.
The sign S represents the similarity in the template of the original size, where 0≦S≦1 is satisfied.
A sign Sc represents a highest similarity in a range of the original template after the reduction, where 0≦Sb1≦1 is satisfied.
The sign α represents the scaling factor of one side of the template, where 0 <α<1 is satisfied.
The sign R1 represents the search window on the original template.
The sign R2 represents the search window on the reduced template.
As shown by the hatched region in FIG. 5 on the lower right portion, the number of matched pixels on the input image does not change.
As shown by the hatched region in FIG. 5 on the lower left portion, when it is assumed that there are sufficient number of pixels which have a potential to match on the template when calculating the similarities on the basis of the normalized histogram intersection, the upper limit of the similarity in the search window R2 on the input image after the reduction of the template is Sc=S/α2 (where α<1).
In reduction, the off-template portion as in expansion does not occur. Therefore, the upper limit of the similarity after the reduction is expressed by a following expression (4).

Sc=S/α2  (4)

When the range of α2 which satisfies Sc<θ is obtained, the following expression (5) is obtained.

S/θ<α2<1  (5)

(1-6) Scaling Factor

When the expression (3) and the expression (5) are combined, and the case of α=1 is included, the upper limit and the lower limit of the α2 are expressed by a flowing expression (6).

S/θ<α2<1/(1+S−θ)  (6)

(1-7) Advantages

In this manner, according to the first embodiment, fast matching is achieved by omitting the matching with the templates whose similarities fall short of the threshold value θ given in advance.
(1-8 First Modification)
In the first modification, a case where the number of matched pixels is limited when the similarities are calculated on the basis of the normalized histogram intersection will be described. In other words, in the first embodiment, it is assumed that there are sufficiently large number of pixels which have a potential to match in the search window with the expanded template. However, if there is a limit, a degree of increase in similarities by the expansion of the template is smaller than the case of the first embodiment, and hence the similarities do not exceed the threshold value θ unless the template is further expanded. By utilizing this feature, the upper limit and the lower limit of the scaling factor α can further be increased.
(1-8-1) Method of Calculating Upper Limit of Scaling Factor
First of all, a method of calculating the upper limit of the scaling factor α in a case where the number of pixels which have a potential to match an expanded template in the search window is limited when calculating the similarities on the basis of the normalized histogram intersection will be described.
The similarity Sb1 after the expansion is not set to a possible maximum value, but is calculated actually. In this modification, since the similarities are calculated on the basis of the normalized histogram intersection, when the upper limit is calculated at every bin of the histogram, an uppermost similarity Sb(α2) after the expansion can be expressed by a following expression (7) by using the expression (1).

Sb(α2)=S(hw, α2ht)+1−1/α2  (7)

Obtaining the range of the α2 which satisfies Sb(α2)<θ is considered. Since the first term S(hw, α2ht) and the third term −1/α2 on the right side of the expression (7) are increased monotonously with α2, Sb(α2) is also increased monotonously with α2. Therefore, the upper limit of α2 is obtained as a solution of Sb(α2)=θ. For example, it is obtained by hill climbing algorithm for inspecting whether an equation is satisfied or not while increasing the value of α2 finely until the equation is satisfied. When a precise solution cannot be obtained, an approximate solution which satisfies Sb(α2)<θ in the vicinity of the precise solution may be obtained.
Therefore, the range of α2 which satisfies Sb(α2)<θ can be expressed by a following expression (8), where f−1(θ) represents the value of α which satisfies a function ƒ(α)=θ.




  
    
      
        
          1
          <
          
            α
            2
          
          <
          
            
              
                f
                5
                
                  -
                  1
                
              
              ⁡
              
                (
                θ
                )
              
            
            ⁢
            
              
            
            ⁢
            where
            ⁢
            
              
            
            ⁢
            
              
                f
                5
              
              ⁡
              
                (
                α
                )
              
            
          
        
        =
        
          
            s
            ⁡
            
              (
              
                
                  h
                  w
                
                ,
                
                  
                    α
                    2
                  
                  ⁢
                  
                    h
                    t
                  
                
              
              )
            
          
          +
          1
          -
          
            1
            
              α
              2
            
          
        
      
    
    
      
        (
        8
        )
      
    
  




(1-8-2) Method of Calculating Lower Limit of Scaling Factor

In a case where the number of pixels which have a potential to match the expanded template in the search window is limited when calculating the similarities on the basis of the normalized histogram intersection in reduction, the lower limit of the scaling factor α can further be reduced. A method of calculating the lower limit thereof will be described below.
The similarity Sc after the reduction is not set to the highest possible value, but is calculated actually. In this modification, since the similarities are calculated on the basis of the normalized histogram intersection, when the lower limit is calculated at every bin of the histogram, a similarity Sc (α2) after the reduction can be expressed by a following expression (9).

Sc(α2)=S(α2hw,ht)  (9)

Obtaining the range of the α2 which satisfies Sc(α2)<θ is considered. Since the right side of an expression (9) is decreased monotonously with α2, Sc(α2) is increased monotonously with α2. Therefore, the lower limit value of α2 is obtained as a solution of the Sc(α2)=θ.
Therefore, the range of α2 which satisfies Sc(α2)<θ can be expressed by a following expression (10).

ƒ6−1(θ)<α2<1 where ƒ6(α)=s(α2hw,ht)  (10)

(1-8-3) Combination

When the expression (8) and the expression (10) are combined, the upper limit and the lower limit of the scaling factor α2 can be expressed by a following expression (11).




  
    
      
        
          
            
              f
              7
              
                -
                1
              
            
            ⁡
            
              (
              θ
              )
            
          
          <
          
            α
            2
          
          <
          
            
              f
              8
              
                -
                1
              
            
            ⁡
            
              (
              θ
              )
            
          
        
        ⁢
        
          

        
        ⁢
        
          
            where
            ⁢
            
              
            
            ⁢
            
              
                f
                7
              
              ⁡
              
                (
                α
                )
              
            
          
          =
          
            
              
                s
                ⁡
                
                  (
                  
                    
                      
                        α
                        2
                      
                      ⁢
                      
                        h
                        w
                      
                    
                    ,
                    
                      h
                      t
                    
                  
                  )
                
              
              ⁢
              
                
              
              ⁢
              
                
                  f
                  8
                
                ⁡
                
                  (
                  α
                  )
                
              
            
            =
            
              
                s
                ⁡
                
                  (
                  
                    
                      h
                      w
                    
                    ,
                    
                      
                        α
                        2
                      
                      ⁢
                      
                        h
                        t
                      
                    
                  
                  )
                
              
              +
              1
              -
              
                1
                
                  α
                  2
                
              
            
          
        
      
    
    
      
        (
        11
        )
      
    
  




(1-8-4) Advantages

In this modification, a throughput of calculation of the upper limit and the lower limit of the scaling factor α is increased. However, in the normal image matching, it is very small when compared with an amount of reduction of the throughput by being able to expand the upper limit and the lower limit of the scaling factor α. Therefore, fast matching is achieved by this modification.
(1-9 Second Modification)
In the second modification, a case of using both the upper limit and the lower limit will be described. In other words, although only one of the lower limit and the upper limit of the scaling factor is used for reducing the template image in the first embodiment, the present invention is not limited thereto, and both the upper limit and the lower limit of the scaling factor may be used.
In this case, the position of the search window in Japanese Patent No. 3474131 is replaced by the scaling factor α, and the similarity is replaced by the similarity S detected in Step 202. A case of matching while expanding the template will be described below.
First of all, the template matching is performed to obtain the highest similarity S. It is assumed that a highest similarity S′ is not changed abruptly at the scaling factor in the periphery of the scaling factor α, it is estimated to be S′=S. When obtaining the lower limit of the scaling factor using the expression (6), √(S/θ) is acquired. A value α′ is estimated so that the lower limit of the scaling factor calculated when the template is multiplied by α′ includes α, and hence the scaling width is continued. Although there are many values of α′ as such, the value of α′=√(S/θ)−γ which is a value returned from the position most apart from α by γ is determined by the limit value calculating unit 104. However, the value of γ is a fixed value. The term “continue” here means a state in which the range of scaling determined by the upper limit and the lower limit of the scaling factor of the previous time and the range of scaling determined by the upper limit and the lower limit of the scaling factor of this time are overlapped with each other. If they are not overlapped with each other, a clearance (the scaling factor which is not searched) is generated between the range of scaling of the previous time and the range of scaling of this time, so that discontinuity is resulted.
Actually, the template is expanded by α′ times to calculate an actual similarity S′′, thereby calculating an upper limit value αupper′ and a lower limit value αlower′ of the actual scaling factor. Since the lower limit value is αlower′=√(S′′/θ), when √(S/θ)≦√(S′′/θ)−γ is satisfied, it is determined that the scaling factor is continued, and if not, it is determined to be discontinued.
When estimation is failed and α is not included in the range of the scaling factor, that is, when the range from the upper limit value αupper′ to the lower limit value αlower′ of the scaling factor and the range from the upper limit value αupper to the lower limit value αlower of the scaling factor of the previous time are not overlapped with each other and are discontinued, a backtrack process for bringing the scaling factor α′ closer to α and trying matching again is performed. The method of bringing the scaling factor α′ closer to a may be any method, such as increasing and decreasing the scaling factor α′ by a fixed width or at a fixed scale factor toward the scaling factor α, or employing an average of α′ and α as a new α′.
When the estimation is successful, the new highest similarity is designated as αmax, and the above-described processes are repeated until the entire scaling range is searched.
According to the modifications, the width of change of the scaling factor may be set to a large width in comparison with the first embodiment, and hence fast matching is achieved. The fast matching is also achieved in the case where matching is performed while reducing the template as in the case described above.
(1-10 Third Modification)
In the third modification, a detailed example of the method of expanding and reducing the template will be described on the basis of FIG. 7 and FIG. 8. In other words, the method of scaling of the template in the first embodiment is preferably a method in which the distribution of the histogram characteristic does not change abruptly before the scaling and after the scaling.
A case of reducing a template image of 4×4 to 2×2 will be described as an example. Respective elements of the template before a reduction are expressed by P1(x, y), and elements after the reduction are expressed by P2(x, y). A sign x represents a row, and a sign y represents a column.
(1-10-1) Problems
FIG. 7 shows a case of reducing a template image from sixteen regions into four regions and averaging brightness values of the respective regions. The maximum value of the brightness value is set to 8, and it is assumed that there are only two brightness values; 0 and 8 before the reduction. Drawings on the lower side in FIG. 7 show a frequency of appearance with respect to the brightness value. Before the reduction, the pixels having the brightness value of 0 are present by the same number as the number of pixels having the brightness value of 8.
When the image is reduced by averaging;

P2(1,1)=(8+0+8+0)/4=4,

P2(1,2)=4,

P2(2,1)=(0+0+8+0)/4=2,

P2(2,2)=(8+8+0+8)/4=6

are obtained.
Therefore, as shown in the distribution maps on the lower side of FIG. 7, the distribution of frequency of the brightness value is significantly changed, and a brightness value different from that before the reduction appears. In the first embodiment, since the similarities are calculated on the basis of the normalized histogram intersection, there is a problem such that the similarity becomes useless when the distribution of histogram characteristics of the brightness value is significantly changed.
(1-10-2) Solving Method
FIG. 8 shows a case of reducing a template image from sixteen regions into four regions and selecting representative pixels at random from the respective regions. In this case, the brightness value which is different from the value before the reduction does not appear and the distribution of the histogram characteristics of the brightness value does not change significantly, so that the normalized histogram intersection can be calculated.
(1-11 Fourth Modification)
In the fourth modification, a case of dividing the input image will be described. In other words, in the first embodiment, the template matching is performed over the entire input image in Step 202. In Step 202, in order to calculate the maximum value S of the similarity of the input image, the scaling factor of the template cannot be changed significantly if the similarity is high only at one point even when the similarity of most part of the input image is zero.
Therefore, the input image may be divided into a plurality of regions to perform the template matching in the respective regions independently. For example, the input image is divided into four regions, and the template matching is performed on each of these regions by regarding each of these regions as an independent image.
Accordingly, the fast searching is achieved even on the input image having only a small part which is similar to the template by searching only the region having a portion similar to the template in detail and increasing the change of the scaling factor for other regions.
It is also possible to regard the respective pixels of the input image as divided regions. When matching while expanding the template, first of all, the upper limit values of scaling factor are stored for the respective pixels in the input image. When the minimum value of the upper limit value is changed as the scaling factor of the next template, the calculation of the similarity is omitted if it is within the range of the upper limit values stored in the respective pixels.
(2 Second Embodiment)
Referring now to FIG. 9 to FIG. 13, a template matching apparatus according to the second embodiment of the invention will be described.
In this embodiment, a case of a one-dimensional search space will be described. In other words, an image matching whose search space has two dimensions has been described in the first embodiment, the template matching apparatus is applied to a one-dimensional search space in this embodiment. More specifically, a speech matching will be described as an example. The term scaling in the speech matching means to scale a speech signal in a direction of time.
A configuration and a procedure of a speech template matching apparatus according to this embodiment are the same as the image template matching apparatus according to the first embodiment, and only the method of calculating the scaling factor in the limit value calculating unit 104 is different. The method will be described below.
(2-1) Expansion
First of all, a case of matching while expanding the template from one time to αupper times (where αupper >1) will be described.
FIG. 9 is an explanatory drawing showing an outline of the speech matching. In the same manner as the case of image matching, a matching with an input speech on the left side in FIG. 9 is performed while scaling templates on the right side in FIG. 9.
FIG. 10 is a drawing for explaining a method of calculating the upper limit of the scaling factor when expanding the template.
An upper portion in FIG. 10 shows a state of matching a template speech having an original size and an input speech and a lower side of FIG. 10 shows a state of matching an expanded template speech and the input speech.
The sign S represents the similarity in the template of the original size, where 0≦S≦1 is satisfied.
The sign Sb1 represents an upper limit value of the similarity in a range of the original template after the expansion, where 0≦Sb1≦1 is satisfied.
A sign Sb2 is the upper limit value of the similarity in an off-template region on a template after the expansion, where 0≦Sb2≦1 is satisfied.
The sign α represents the scaling factor of one side of the template, where 1<α is satisfied.
Then, the number of matched pixels on the expanded template is increased to a times as shown by a hatched region on the lower left portion in FIG. 10. As shown by a hatched region on the lower right portion in FIG. 10, when it is assumed that there are sufficient number of pixels which have a potential to match on the input image when calculating the similarities on the basis of the normalized histogram intersection, the upper limit of the similarity in the original template after expansion is Sb1=S.
In contrast, an entire off-R1 region of the expanded template is able to contribute to increase in similarity. Therefore, the highest similarity in the off R−1 region is Sb2=1−1/α. Therefore, the upper limit of similarities after the expansion is expressed by a following expression (12).

Sb=Sb1+Sb2=1+S−1/α  (12)

When the region of a which satisfies Sb<θ, it is expressed by a following expression (13).

1<α<1/(1+S−θ), where S>θ is satisfied  (13)

(2-2) Reduction

Subsequently, a case of matching while reducing the template from one time to αlower times (where αlower<1) will be described.
As shown by a hatched region in FIG. 11 on the lower right portion, the number of matched samples on the input speech does not change. As shown by a hatched region in FIG. 11 on the lower left portion, when it is assumed that there are sufficient number of samples which have a potential to match on the template when calculating the similarity on the basis of the normalized histogram intersection, the upper limit of the similarity in the input speech after the reduction of the template is Sc=S/α (where α<1).
In reduction, the off-template portion as in expansion does not occur. Therefore, the upper limit of similarities after the reduction is expressed by a following expression (14).

Sc=S/α  (14)

When the range of α which satisfies Sc<θ is obtained, a following expression (15) is obtained.

S/θ<α<1  (15)

(2-3) Combination

When the expression (13) and the expression (15) are combined, the upper limit and the lower limit of the scaling factor α can be expressed by a following expression (16).

S/θ<α<1/(1+S−θ)  (16)

(2-4) Advantages

In this manner, according to this embodiment, when matching the voice signals, the upper limit and the lower limit of a scaling factor are obtained by the expression (16) in which the α2 of the image matching is replaced by α.
FIG. 13 shows a result of comparison of a process time in the voice matching according to the second embodiment and the process time of the method in the related art. As shown in FIG. 13, 20 times faster process is achieved.
(2-5) Modification
When the number of pixels which have a potential to match the expanded template in the search window is limited as in the first modification of the first embodiment, it can be expressed by a following expression (17) in which α2 in the expression (15) is replaced by α.

ƒ9−1(θ)<α<ƒ10−1(θ)

where

ƒ9(α)=s(αhw,ht) f10(α)=s(hw,αht)+1−1/α. . .   (17)

(3 Third Embodiment)

A template matching apparatus according to the third embodiment of the present invention will be described.
In this embodiment, a case of an n-dimensional search space will be described. In other words, the case where the image matching whose search space has two dimensions has been described as an example in the first embodiment, and the speech matching whose search space has one dimension has been described as an example in the second embodiment. In this embodiment, a case of being expanded to a signal matching in the n-dimensional search space will be described.
When calculating the similarity on the basis of the normalized histogram intersection in scaling, if there are sufficiently large number of signals which have a potential to match, the upper limit and the lower limit of the scaling factor αn can be expressed by a following expression (18).

S/θ<αn<1/(1+S−θ)  (18)

In the same manner as the first modification of the first embodiment when calculating the similarity on the basis of the normalized histogram intersection, if the number of pixels which have a potential to match the expanded template in the search window is limited, when considering that the signals which match in scaling is limited, the upper limit and the lower limit of scaling factor αn can be expressed by a following expression (19).

ƒ11−1(θ)<αn<f12−1(θ)

where

f11(α)=s(αnhw,ht) f12(α)=s(hw,αnht)+1−1/αn . . .   (19)

(4 Fourth Embodiment)

Referring now to FIG. 14, a template matching apparatus according to the fourth embodiment of the present invention will be described.
In this embodiment, a case where the scaling factors are independent in the respective dimensions will be described. In other words, in the respective embodiments in which the search space has two or more dimensions described thus far, the scaling factors in the respective dimensions are equal. However, in this embodiment, a case where the scaling factors in the respective dimensions are different will be described.
(4-1) Case of Two Dimensions
Referring now to FIG. 14, a method of calculating the upper limit of the scaling factor when scaling the template in a case of image matching which is a two-dimensional search space will be described. FIG. 14 is almost the same as FIG. 4, but is different in that the scaling factors of the template are α1 in the vertical direction and α2 in the horizontal direction, which are not equal.
As shown by a hatched region on the lower left portion in FIG. 14, the number of matched pixels on the expanded template is increased to α1×α2 times. As shown by a hatched area on the lower right portion in FIG. 14, when it is assumed that there are sufficient number of pixels which have a potential for matching on the input image when calculating the similarities on the basis of the normalized histogram intersection, the upper limit of the similarity in the original template in the search window R1 after expansion is Sb1=S.
In contrast, an entire off-R1 region in the search window R2 of the expanded template is able to contribute to increase in similarity. Therefore, in the case of α1>1, α2<1 as shown in FIG. 14, the highest similarity of the off-R1 region is

Sb2=1−1/α1×1.

When it is expressed generally considering that the off-R1 region is eliminated when the side is reduced, it can be expressed by:

Sb2=1−min(1,1/α1)×min(1,1/α2).

Therefore, the upper limit of similarities after the expansion is expressed by a following expression (20);

Sb=Sb1+Sb2=S+1−min(1,1/α1)×(1,1/α2)  (20)

where the function min (*) is a function which outputs a minimum value of two variables.

(4-2) Case of n Dimensions

Subsequently, a case of n dimensions, which is more general, will be described.
When there are sufficient signals which match the input signal as shown in FIG. 1,

Sb1=S,

Sb2=1−min(1,1/α1)×min(1,1/α2)× . . . ×min(1,1/αn) are satisfied.

In this case, the upper limit in scaling factor is provided.
As shown in FIG. 5, when there are sufficient signals which match the template when calculating the similarities on the basis of the normalized histogram intersection,

Sb1=S/(min(1,1/α1)×min(1,1/α2)× . . . ×min(1,1/αn)),

Sb2=1−min(1,1/α1)×min(1,1/α2)× . . . ×min(1,1/αn) are satisfied.

In this case, the lower limit in scaling factor is provided.
Therefore, the upper limit and the lower limit of an n-dimensional scaling factor vector α can be expressed by a following expression (21).




  
    
      
        
          
            
              f
              13
              
                -
                1
              
            
            ⁡
            
              (
              θ
              )
            
          
          <
          α
          <
          
            
              f
              14
              
                -
                1
              
            
            ⁡
            
              (
              θ
              )
            
          
        
        ⁢
        
          

        
        ⁢
        
          
            where
            ⁢
            
              
            
            ⁢
            
              
                f
                13
              
              ⁡
              
                (
                α
                )
              
            
          
          =
          
            
              s
              
                
                  ∏
                  
                    i
                    =
                    1
                  
                  n
                
                ⁢
                
                  
                
                ⁢
                
                  1
                  
                    α
                    i
                  
                
              
            
            +
            1
            -
            
              
                ∏
                
                  i
                  =
                  1
                
                n
              
              ⁢
              
                
              
              ⁢
              
                min
                ⁡
                
                  (
                  
                    1
                    ,
                    
                      1
                      
                        α
                        i
                      
                    
                  
                  )
                
              
            
          
        
        ⁢
        
          

        
        ⁢
        
          
            
              f
              14
            
            ⁡
            
              (
              α
              )
            
          
          =
          
            s
            +
            1
            -
            
              
                ∏
                
                  i
                  =
                  1
                
                n
              
              ⁢
              
                
              
              ⁢
              
                min
                ⁡
                
                  (
                  
                    1
                    ,
                    
                      1
                      
                        α
                        i
                      
                    
                  
                  )
                
              
            
          
        
      
    
    
      
        (
        21
        )
      
    
  




α1 is an element of vector α
(4-3) Modification
When the number of pixels which has a potential to match the expanded template in the search window is limited when calculating the similarities on the basis of the normalized histogram intersection as in the first modification of the first embodiment, the upper limit and the lower limit of the scaling factor vector α can be expressed by a following expression (22).




  
    
      
        
          
            
              f
              15
              
                -
                1
              
            
            ⁡
            
              (
              θ
              )
            
          
          <
          α
          <
          
            
              f
              16
              
                -
                1
              
            
            ⁡
            
              (
              θ
              )
            
          
        
        ⁢
        
          

        
        ⁢
        
          
            where
            ⁢
            
              
            
            ⁢
            
              
                f
                15
              
              ⁡
              
                (
                α
                )
              
            
          
          =
          
            
              
                s
                ⁡
                
                  (
                  
                    
                      α
                      ·
                      I
                      ·
                      
                        h
                        w
                      
                    
                    ,
                    
                      h
                      t
                    
                  
                  )
                
              
              
                
                  ∏
                  
                    i
                    =
                    1
                  
                  n
                
                ⁢
                
                  
                
                ⁢
                
                  1
                  
                    α
                    i
                  
                
              
            
            +
            1
            -
            
              
                ∏
                
                  i
                  =
                  1
                
                n
              
              ⁢
              
                
              
              ⁢
              
                min
                ⁡
                
                  (
                  
                    1
                    ,
                    
                      1
                      
                        α
                        i
                      
                    
                  
                  )
                
              
            
          
        
        ⁢
        
          

        
        ⁢
        
          
            
              f
              16
            
            ⁡
            
              (
              α
              )
            
          
          =
          
            
              s
              ⁡
              
                (
                
                  
                    h
                    w
                  
                  ,
                  
                    α
                    ·
                    I
                    ·
                    
                      h
                      t
                    
                  
                
                )
              
            
            +
            1
            -
            
              
                ∏
                
                  i
                  =
                  1
                
                n
              
              ⁢
              
                
              
              ⁢
              
                min
                ⁡
                
                  (
                  
                    1
                    ,
                    
                      1
                      
                        α
                        i
                      
                    
                  
                  )
                
              
            
          
        
      
    
    
      
        (
        22
        )
      
    
  




where αi is an element of vector α and I represents a unit vector
(5 Fifth Embodiment)
In a fifth embodiment, a case of using a distance to be calculated by a norm of the brightness average value as a similarity used in the first embodiment will be described. In other words, in the embodiments described thus far, the normalized histogram intersection between the histogram of the amount of characteristics of the template image and the histogram of the amount of characteristic of the input image is calculated in Step 203. However, the method of calculating the similarity may be of any method as long as the upper limit of the similarity is obtained by the scaling of the template image.
Here, as an example, a case where an L1 norm of an average brightness, that is, an absolute value of a difference is used will be described. However, when using distances instead of the similarities, the meaning of the magnitude of a numerical value is inverted, and hence it is necessary to pay attention when obtaining the upper limit of the similarity.
(5-1) Method of Calculating Upper Limit of Scaling Factor in Expansion
A case of expanding the template image will be descried first. Where c1 and c2 are average brightness values of the template image and the input image respectively and θ is a threshold value, the distance is obtained by D=|ci−c2|, and |*| outputs the absolute value. A case of c2−c1>θ and a case of c1−c2>θ are described separately.
(5-1-1) When c2−c1>θ in Expansion
A case where the average brightness c1 of the input image is larger than the average brightness c2 of the template image, and reducing an average brightness c2′ after expansion in the search window set on the input image are considered. Assuming that the entire part of a run-off region after expansion contributes to a reduction of average brightness c2′, c2′=c2/α2 is satisfied. Therefore, the distance after the expansion, Db=c2′−c1 will be Db=c2/α2−c1. When α2 is solved on the basis of Db>θ;

α2<c2/(c1+θ)  (23)

is satisfied.

(5-1-2) When c1−c2>θ in Expansion

A case where the average brightness c1 of the input image is smaller than the average brightness c2 of the template image, and increasing the average brightness c2′ after expansion in the search window set on the input image are considered. Assuming that the entire part of the run-off region after expansion contributes to an increase of average brightness c2′, c2′=(c2+α2−1)/α2 is satisfied. Therefore, the distance after the expansion, Db=c1−c2′ will be Db=c1−(c2+α2−1)/α2. When α2 is solved on the basis of Db>θ;

α2<(1−c2)/(1−c1+θ)  (24)

is satisfied.

(5-2) Method of Calculating Upper Limit of Scaling Factor in Reduction

The case of c2−c1>θ and the case of c1−c2>θ will be described separately in reduction as well.
(5-2-1) When c2−c1>θ in Reduction
A case where the average brightness c1 of the input image is larger than the average brightness c2 of the template image and reducing the average brightness c2′ after reduction in the search window set on the input image are considered. Assuming that the entire part of an off-search window region after reduction contributes to a decrease of average brightness c2′, c2°=(c1+α2−1)/α2 is satisfied. Therefore, the distance after the reduction, Dc=c2′−c1 will be Dc=(c1+α2−1)/α2−c1. When α2 is solved on the basis of Dc>θ,

α2>(1−c2)/(1−c1−θ)  (25)

is satisfied.

(5-2-2) When c1−c2>θ in Reduction

A case where the average brightness c1 of the input image is smaller than the average brightness c2 of the template image, and increasing the average brightness c2′ after reduction in the search window set on the input image are considered. Assuming that the entire part of the off-search window region after reduction contributes to an increase of average brightness c2′, c2′=c2/α2 is satisfied. Therefore, the distance after the reduction, De=c1−c2′ will be c1−c2/α2. When α2 is solved on the basis of Dc>θ;

α2>c2/(c1−θ)  (26)

is satisfied.

(5-3) Combination

When the expression (23) and the expression (24) are combined, if c2−c1>θ,

(1−c2)/(1−C1−θ)<α2<c2/(c1+θ)  (27)

is satisfied.

When the expression (24) and the expression (26) are combined, if c1−c2>θ,

c2/(C1−θ)<α2<(1−c2)/(1−c1+θ)  (28)

is satisfied.

(5-4) Modification

Although the L1 norm is used as the method of calculating the distance in the fifth embodiment, L2 norm which is the sum of squared of the difference, or Ln norm which is the sum of nth power of the difference may be used.
Although the image matching whose search space has two dimensions has been described as an example in the fifth embodiment, the speech matching whose search space has one dimension, or the search space having n dimensions may also be applicable. In such a case, α2 in the expression (27) and the expression (28) is replaced by a in the case of one dimension, and αn in the case of the n dimensions.
Alternatively, any method of calculating the distance may be employed as long as the lower limit of the distance is obtained and the norm does not necessarily have to be used. In the case of the similarities, any method may be employed as long as the upper limit of the similarity is obtained.
(6 Modifications)
The present invention is not limited to the respective embodiments exactly as described above, but the components may be modified without departing the scope of the invention in the stage of embodiments.
Also, various modes of the invention are achieved by combining a plurality of components disclosed in the embodiments described above as needed. For example, several components may be eliminated from all the components shown in the embodiment.
In addition, the components in different embodiments may be combined as needed.

## Claims

1. A template matching apparatus comprising:
a signal input unit configured to input an input signal;
a matching unit configured to (1) obtain similarities between the input signal and a template at different search positions on the input signal, the template being an initial template having a predetermined initial size or a scaled template obtained by expanding or reducing the initial template by a given scaling factor, (2) obtain the similarities on the basis of a distribution of amount of characteristics of the template and a distribution of amount of characteristics in a search window on the input signal at respective search positions, and (3) obtain a highest similarity from among the similarities;
a limit value calculating unit configured to calculate an upper limit value of expansion or a lower limit value of reduction of the scaling factor of the template from the highest similarity so that the highest similarity obtained when the template is expanded or reduced does not exceed a threshold value;
a scaling unit configured to expand or reduce the template on the basis of the scaling factor within the upper limit value of expansion or the lower limit value of reduction; and
a repeat control unit configured to expand and reduce the template, by the scaling unit, until a template having a size included in a given range is achieved and repeat searching on the basis of the expanded or reduced template by the matching unit.

2. A template matching apparatus comprising:
a signal input unit configured to input an input signal;
a first matching unit configured to (1) obtain first similarities between the input signal and a template at different search positions on the input signal, the template being an initial template having a predetermined initial size or a scaled template obtained by expanding or reducing the initial template by a given scaling factor, (2) obtain the first similarities on the basis of a distribution of amount of characteristics of the template and a distribution of amount of characteristics in a search window on the input signal at respective search positions, and (3) obtain a highest first similarity from among the first similarities;
an estimating unit configured to estimate an estimated highest similarity for the input signal when the template is expanded or reduced on the basis of the highest first similarity;
a first limit value calculating unit configured to calculate an upper limit value and a lower limit value of the scaling factor of the template from the estimated highest similarity so that a highest similarity when the template is expanded or reduced does not exceed a threshold value;
a scaling unit configured to scale the template by the scaling factor within the scaling range determined by the upper limit value and the lower limit value;
a second matching unit configured to (1) obtain second similarities between the input signal and the scaled template while moving a search position on the input signal, (2) obtain the second similarities on the basis of a distribution of amount of characteristics on the scaled template and a distribution of amount of characteristics in a search window on the input signal at respective search positions and (3) obtain a highest second similarity among the second similarities;
a second limit value calculating unit configured to calculate a scaling range including an upper limit value of expansion or a lower limit value of reduction of the scaling factor of the template from the highest second similarity so that a highest similarity when the template is expanded or reduced does not exceed the threshold value;
a backtrack unit configured to change the scaling factor used in the scaling unit when the scaling range obtained by the second limit value calculating unit and the scaling range whereby a size of the template used by the first matching unit for searching is determined are not overlapped;
a renewing unit configured to control the estimating unit to use the highest second similarity instead of the highest first similarity when the scaling range obtained by the second limit value calculating unit and the scaling range whereby the size of the template used by the first matching unit for searching is determined are overlapped; and
a repeat control unit configured to expand or reduce the template, by the scaling unit, until the size of the template reaches a given range and repeat the search by the template expanded or reduced, by the first matching unit and the second matching unit.

3. The template matching apparatus according to claim 2, wherein when the first limit value calculating unit or the second limit value calculating unit expands or reduces the template having n dimensions at the scaling factor α (where, α>0) which is a scaling factor in which the lengths of all dimensions of the n-dimensional template are the same scale, the first limit value calculating unit or the second limit value calculating unit calculates the upper limit value and the lower limit value of the scaling factor α by:


S/θ<αn<1/(1+S−θ)  (A)


where S (0≦S≦1) is a highest similarity of a previous time calculated by the first matching unit or the second matching unit, and θ (0≦θ≦1) is the threshold value.

4. The template matching apparatus according to claim 2, wherein the first matching unit or the second matching unit calculates the similarities on the basis of a normalized histogram intersection.

5. The template matching apparatus according to claim 4, wherein when expanding or reducing the template having n dimensions are scaled at the scaling factor α (α>0) which is the scaling factor in which the lengths of all dimensions of the n-dimensional template are the same scale, the first matching unit or the second matching unit calculates a highest similarity of this time by a function S (*) shown by an expression (B), where S (0≦S ≦1) is a highest similarity calculated by a search of the previous time by the first matching unit or the second matching unit, θ (0≦θ≦1) is the threshold value, hw and ht are m-dimensional vectors which represent a histogram as the distribution of the amount of characteristics in the search window on the input signal and the distribution of the amount of characteristics of the template respectively, and hwi, hti are ith histogram elements of the amount of characteristics in the search window on the input signal and the amount of characteristics of the template respectively,
wherein the the first limit value calculating unit or the second limit value calculating unit calculates the upper limit value and the lower limit value of the scaling factor α by a following expression (C);





  
    
      
        
          
            s
            ⁡
            
              (
              
                
                  h
                  w
                
                ,
                
                  h
                  t
                
              
              )
            
          
          =
          
            
              ∑
              
                i
                =
                1
              
              n
            
            ⁢
            
              min
              ⁡
              
                (
                
                  
                    h
                    wi
                  
                  ,
                  
                    h
                    ti
                  
                
                )
              
            
          
        
        ⁢
        
          

        
        ⁢
        
          
            
              f
              1
              
                -
                1
              
            
            ⁡
            
              (
              θ
              )
            
          
          <
          
            α
            n
          
          <
          
            
              f
              2
              
                -
                1
              
            
            ⁡
            
              (
              θ
              )
            
          
        
        ⁢
        
          

        
        ⁢
        
          
            
              f
              1
            
            ⁡
            
              (
              α
              )
            
          
          =
          
            s
            ⁡
            
              (
              
                
                  α
                  n
                
                ,
                
                  h
                  w
                
                ,
                
                  h
                  t
                
              
              )
            
          
        
      
    
    
      
        (
        B
        )
      
    
  
  
    
      
        
          
            f
            2
          
          ⁡
          
            (
            α
            )
          
        
        =
        
          
            s
            ⁡
            
              (
              
                
                  h
                  w
                
                ,
                
                  
                    α
                    n
                  
                  ⁢
                  
                    h
                    t
                  
                
              
              )
            
          
          +
          1
          -
          
            1
            
              α
              n
            
          
        
      
    
    
      
        (
        C
        )
      
    
  



where f(θ)−1 outputs the scaling factor α which is a vector satisfying f(α)=θ.

6. The template matching apparatus according to claim 2, wherein when expanding or reducing at the scaling factor αi (αi>0 and 1<i<n) in which the lengths of respective dimensions of the n-dimensional template are different, the first limit value calculating unit or the second limit value calculating unit calculates the upper limit value and the lower limit value of the scaling factor α by a following expression (D);




  
    
      
        
          
            
              f
              3
              
                -
                1
              
            
            ⁡
            
              (
              θ
              )
            
          
          <
          α
          <
          
            
              f
              4
              
                -
                1
              
            
            ⁡
            
              (
              θ
              )
            
          
        
        ⁢
        
          

        
        ⁢
        
          
            
              f
              3
            
            ⁡
            
              (
              α
              )
            
          
          =
          
            
              s
              
                
                  ∏
                  
                    i
                    =
                    1
                  
                  n
                
                ⁢
                
                  
                
                ⁢
                
                  1
                  
                    α
                    i
                  
                
              
            
            +
            1
            -
            
              
                ∏
                
                  i
                  =
                  1
                
                n
              
              ⁢
              
                
              
              ⁢
              
                min
                ⁡
                
                  (
                  
                    1
                    ,
                    
                      1
                      
                        α
                        i
                      
                    
                  
                  )
                
              
            
          
        
        ⁢
        
          

        
        ⁢
        
          
            
              f
              4
            
            ⁡
            
              (
              α
              )
            
          
          =
          
            s
            +
            1
            -
            
              
                ∏
                
                  i
                  =
                  1
                
                n
              
              ⁢
              
                
              
              ⁢
              
                
                  min
                  ⁡
                  
                    (
                    
                      1
                      ,
                      
                        1
                        
                          α
                          i
                        
                      
                    
                    )
                  
                
                .
              
            
          
        
      
    
    
      
        (
        D
        )

7. The template matching apparatus according to claim 2, wherein the first matching unit or the second matching unit divides the input signals into a plurality of regions and performs the search individually for the respective divided regions.

8. The template matching apparatus according to claim 2, wherein the first matching unit or the second matching unit calculates the similarity using a norm on the basis of an average brightness value.

9. A computer-implemented template matching method executed by a processor of a computer apparatus, the method comprising:
inputting an input signal;
(1) obtaining first similarities between the input signal and a template at different search positions on the input signal, the template being an initial template having a predetermined initial size or a scaled template obtained by expanding or reducing the initial template by a given scaling factor, (2) obtaining the first similarities on the basis of a distribution of an amount of characteristics of the template and a distribution of an amount of characteristics in a search window on the input signal at respective search positions, and (3) obtaining a highest first similarity from among the first similarities;
estimating an estimated highest similarity for the input signal when the template is expanded or reduced on the basis of the highest first similarity;
calculating an upper limit value and a lower limit value of the scaling factor of the template from the estimated highest similarity so that a highest similarity when the template is expanded or reduced does not exceed a threshold value;
scaling the template by the scaling factor within the scaling range determined by the upper limit value and the lower limit value;
(1) obtaining second similarities between the input signal and the scaled template while moving a search position on the input signal, (2) obtaining the second similarities on the basis of a distribution of the amount of characteristics on the scaled template and a distribution of the amount of characteristics in a search window on the input signal at respective search positions, and (3) obtaining a highest second similarity among the second similarities;
calculating a scaling range including an upper limit value of expansion or a lower limit value of reduction of the scaling factor of the template from the highest second similarity so that a highest similarity when the template is expanded or reduced does not exceed the threshold value;
changing the scaling factor when the scaling range including the upper limit value of expansion or the lower limit value of reduction of the scaling factor of the template and the scaling range whereby a size of the template used to obtain the first similarities is determined are not overlapped;
controlling the highest second similarity to be used in the estimating instead of the highest first similarity when the scaling range including the upper limit value of expansion or the lower limit value of reduction of the scaling factor of the template and the scaling range whereby the size of the template used to obtain the first similarities are overlapped; and
expanding or reducing the template until the size of the template reaches a given range and repeating the search on the basis of the expanded or reduced template.

10. A non-transitory computer-readable medium including a template matching program stored thereon, which when executed, causes a computer, to perform operations comprising:
inputting an input signal;
(1) obtaining first similarities between the input signal and a template at different search positions on the input signal, the template being an initial template having a predetermined initial size or a scaled template obtained by expanding or reducing the initial template by a given scaling factor, (2) obtaining the first similarities on the basis of a distribution of an amount of characteristics of the template and a distribution of an amount of characteristics in a search window on the input signal at respective search positions, and (3) obtaining a highest first similarity from among the first similarities;
estimating an estimated highest similarity for the input signal when the template is expanded or reduced on the basis of the highest first similarity;
calculating an upper limit value and a lower limit value of the scaling factor of the template from the estimated highest similarity so that a highest similarity when the template is expanded or reduced does not exceed a threshold value;
scaling the template by the scaling factor within the scaling range determined by the upper limit value and the lower limit value;
(1) obtaining second similarities between the input signal and the scaled template while moving a search position on the input signal, (2) obtaining the second similarities on the basis of a distribution of the amount of characteristics on the scaled template and a distribution of the amount of characteristics in a search window on the input signal at respective search positions, and (3) obtaining a highest second similarity among the second similarities;
calculating a scaling range including an upper limit value of expansion or a lower limit value of reduction of the scaling factor of the template from the highest second similarity so that a highest similarity when the template is expanded or reduced does not exceed the threshold value;
changing the scaling factor when the scaling range including the upper limit value of expansion or the lower limit value of reduction of the scaling factor of the template and the scaling range whereby a size of the template used to obtain the first similarities is determined are not overlapped;
controlling the highest second similarity to be used in the estimating instead of the highest first similarity when the scaling range including the upper limit value of expansion or the lower limit value of reduction of the scaling factor of the template and the scaling range whereby the size of the template used to obtain the first similarities are overlapped; and
expanding or reducing the template until the size of the template reaches a given range and repeating the search on the basis of the expanded or reduced template.