Efficient Sliding Window Computation for NN-Based Template Matching

  • Lior TalkerEmail author
  • Yael Moses
  • Ilan Shimshoni
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11214)


Template matching is a fundamental problem in computer vision, with many applications. Existing methods use sliding window computation for choosing an image-window that best matches the template. For classic algorithms based on SSD, SAD and normalized cross-correlation, efficient algorithms have been developed allowing them to run in real-time. Current state of the art algorithms are based on nearest neighbor (NN) matching of small patches within the template to patches in the image. These algorithms yield state-of-the-art results since they can deal better with changes in appearance, viewpoint, illumination, non-rigid transformations, and occlusion. However, NN-based algorithms are relatively slow not only due to NN computation for each image patch, but also since their sliding window computation is inefficient. We therefore propose in this paper an efficient NN-based algorithm. Its accuracy is similar (in some cases slightly better) than the existing algorithms and its running time is 43–200 times faster depending on the sizes of the images and templates used. The main contribution of our method is an algorithm for incrementally computing the score of each image window based on the score computed for the previous window. This is in contrast to computing the score for each image window independently, as in previous NN-based methods. The complexity of our method is therefore O(|I|) instead of O(|I||T|), where I and T are the image and the template respectively.



This work was partially supported by the Israel Science Foundation, grant no. 930/12, and by the Israeli Innovation Authority in the Ministry of Economy and Industry.

Supplementary material

474197_1_En_25_MOESM1_ESM.pdf (26.4 mb)
Supplementary material 1 (pdf 27012 KB)


  1. 1.
    Bertinetto, L., Valmadre, J., Henriques, J.F., Vedaldi, A., Torr, P.H.S.: Fully-convolutional siamese networks for object tracking. In: Hua, G., Jégou, H. (eds.) ECCV 2016. LNCS, vol. 9914, pp. 850–865. Springer, Cham (2016). Scholar
  2. 2.
    Bradski, G.: The OpenCV Library. Dr. Dobb’s Journal of Software Tools (2000)Google Scholar
  3. 3.
    Felzenszwalb, P.F., Huttenlocher, D.P.: Pictorial structures for object recognition. Int. J. Comput. Vis. 61(1), 55–79 (2005)CrossRefGoogle Scholar
  4. 4.
    Held, D., Thrun, S., Savarese, S.: Learning to track at 100 FPS with deep regression networks. In: Leibe, B., Matas, J., Sebe, N., Welling, M. (eds.) ECCV 2016. LNCS, vol. 9905, pp. 749–765. Springer, Cham (2016). Scholar
  5. 5.
    Korman, S., Reichman, D., Tsur, G., Avidan, S.: Fast-match: fast affine template matching. In: Proceedings of IEEE Conference on Computer Vision and Pattern Recognition, pp. 2331–2338 (2013)Google Scholar
  6. 6.
    Mercier, J.P., Trottier, L., Giguere, P., Chaib-draa, B.: Deep object ranking for template matching. In: IEEE Winter Conference on Applications of Computer Vision (WACV), pp. 734–742 (2017)Google Scholar
  7. 7.
    Moudgil, A., Gandhi, V.: Long-term visual object tracking benchmark. arXiv preprint arXiv:1712.01358 (2017)
  8. 8.
    Muja, M., Lowe, D.G.: Scalable nearest neighbor algorithms for high dimensional data. IEEE Trans. Pattern Anal. Mach. Intell. 36 (2014)CrossRefGoogle Scholar
  9. 9.
    Oron, S., Dekel, T., Xue, T., Freeman, W.T., Avidan, S.: Best-buddies similarity-robust template matching using mutual nearest neighbors. IEEE Trans. Pattern Anal. Mach. Intell. (2017)Google Scholar
  10. 10.
    Ouyang, W., Tombari, F., Mattoccia, S., Di Stefano, L., Cham, W.-K.: Performance evaluation of full search equivalent pattern matching algorithms. IEEE Trans. Pattern Anal. Mach. Intell. 34(1), 127–143 (2012)CrossRefGoogle Scholar
  11. 11.
    Penate-Sanchez, A., Porzi, L., Moreno-Noguer, F.: Matchability prediction for full-search template matching algorithms. In: International Conference on 3D Vision (3DV), pp. 353–361 (2015)Google Scholar
  12. 12.
    Simonyan, K., Zisserman, A.: Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556 (2014)
  13. 13.
    Talmi, I., Mechrez, R., Zelnik-Manor, L.: Template matching with deformable diversity similarity. In: Proceedings of IEEE Conference on Computer Vision and Pattern Recognition (2017)Google Scholar
  14. 14.
    Tian, Y., Narasimhan, S.G.: Globally optimal estimation of nonrigid image distortion. Int. J. Comput. Vis. 98(3), 279–302 (2012)MathSciNetCrossRefGoogle Scholar
  15. 15.
    Wei, Y., Tao, L.: Efficient histogram-based sliding window. In: Proceedings of IEEE Confernece on Computer Vision Pattern Recognition, pp. 3003–3010 (2010)Google Scholar
  16. 16.
    Wu, Y., Lim, J., Yang, M.H.: Online object tracking: a benchmark. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 2411–2418 (2013)Google Scholar
  17. 17.
    Zagoruyko, S., Komodakis, N.: Learning to compare image patches via convolutional neural networks. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 4353–4361 (2015)Google Scholar
  18. 18.
    Zbontar, J., LeCun, Y.: Stereo matching by training a convolutional neural network to compare image patches. J. Mach. Learn. Res. 17(1–32), 2 (2016)zbMATHGoogle Scholar
  19. 19.
    Zhang, C., Akashi, T.: Fast affine template matching over Galois field. In: British Machine Vision Conference (BMVC), pp. 121.1–121.11 (2015)Google Scholar

Copyright information

© Springer Nature Switzerland AG 2018

Authors and Affiliations

  1. 1.The University of HaifaHaifaIsrael
  2. 2.The Interdisciplinary CenterHerzliyaIsrael

Personalised recommendations