跳至內容

模板匹配

本頁使用了標題或全文手工轉換
維基百科,自由的百科全書

模板匹配(英語:Template matching[1]數碼圖像處理中用於將模板圖像匹配目標圖像其中一小部分的技術。在常被用於製作業中的質素控制[2]機械人導航英語robotic navigation[3]或圖像邊緣檢測[4]

模板匹配的最大挑戰是遮擋檢測,在這種情況下,所需的對象部分隱藏在圖像中;此外,當物體扭曲或從不同角度成像時,檢測非剛性變換亦為挑戰之一。其它挑戰因素包括圖像對照明和背景變化的敏感性、圖像背景雜亂,以及圖像尺度變化[5]

傳統的模板匹配方法包括交叉相關(Cross Correlation)和絕對差和(Sum of Absolute Differences, SAD)法。隨着機器學習領域的進步,使用深度神經網絡(如 卷積神經網絡)進行特徵提取已被證明極其有效,並已成為最先進的模板匹配演算法的標準[6]。這種基於特徵的方法通常比傳統的模板匹配方法更具有魯棒性,並且可以匹配具有非剛性和平面外變換以及高背景雜波和光照變化的模板[7][8][9]

實現

[編輯]

在這個簡單的實現中,模板匹配方法應用於灰度圖像,通過絕對差和法,最終將給出模板圖像與搜尋圖像最匹配的左上角位置。

minSAD = VALUE_MAX;

// 在匹配的图像中进行循环
for ( size_t x = 0; x <= S_cols - T_cols; x++ ) {
    for ( size_t y = 0; y <= S_rows - T_rows; y++ ) {
        SAD = 0.0;

        // 在模板的图像中进行循环
        for ( size_t j = 0; j < T_cols; j++ )
            for ( size_t i = 0; i < T_rows; i++ ) {

                pixel p_SearchIMG = S[y+i][x+j];
                pixel p_TemplateIMG = T[i][j];
		
                SAD += abs( p_SearchIMG.Grey - p_TemplateIMG.Grey );
            }

        // 保存寻找到的最佳位置
        if ( minSAD > SAD ) { 
            minSAD = SAD;
            position.bestRow = y;
            position.bestCol = x;
            position.bestSAD = SAD;
        }
    }
    
}

對彩色圖像執行模板匹配的一種方法是將像素分解為其顏色分量,並使用分別為每種顏色計算的SAD之和來測量顏色模板和搜尋圖像之間的匹配質素。

參見

[編輯]

參考來源

[編輯]
  1. ^ R. Brunelli, Template Matching Techniques in Computer Vision: Theory and Practice, Wiley, ISBN 978-0-470-51706-2, 2009 ([1]頁面存檔備份,存於互聯網檔案館) TM book)
  2. ^ Aksoy, M. S.; Torkul, O.; Cedimoglu, I. H. An industrial visual inspection system that uses inductive learning. Journal of Intelligent Manufacturing. 2004, 15 (4): 569–574. S2CID 35493679. doi:10.1023/B:JIMS.0000034120.86709.8c. 
  3. ^ Kyriacou, Theocharis, Guido Bugmann, and Stanislao Lauria. "Vision-based urban navigation procedures for verbally instructed robots頁面存檔備份,存於互聯網檔案館)." Robotics and Autonomous Systems 51.1 (April 30, 2005): 69-80. Expanded Academic ASAP. Thomson Gale.
  4. ^ WANG, CHING YANG, Ph.D. "EDGE DETECTION USING TEMPLATE MATCHING (IMAGE PROCESSING, THRESHOLD LOGIC, ANALYSIS, FILTERS)". Duke University, 1985, 288 pages; AAT 8523046
  5. ^ Talmi, Itamar; Mechrez, Roey; Zelnik-Manor, Lihi. Template Matching with Deformable Diversity Similarity. 2016-12-07. arXiv:1612.02190可免費查閱 [cs.CV]. 
  6. ^ Zhang, Richard; Isola, Phillip; Efros, Alexei A.; Shechtman, Eli; Wang, Oliver. The Unreasonable Effectiveness of Deep Features as a Perceptual Metric. 2018-01-11. arXiv:1801.03924可免費查閱 [cs.CV]. 
  7. ^ Talmi, Mechrez, Zelnik-Manor. Template Matching with Deformable Diversity Similarity. 2016. arXiv:1612.02190可免費查閱 [cs.CV]. 
  8. ^ Li, Yuhai, L. Jian, T. Jinwen, X. Honbo. 「A fast rotated template matching based on point feature頁面存檔備份,存於互聯網檔案館).」 Proceedings of the SPIE 6043 (2005): 453-459. MIPPR 2005: SAR and Multispectral Image Processing.
  9. ^ B. Sirmacek, C. Unsalan. 「Urban Area and Building Detection Using SIFT Keypoints and Graph Theory頁面存檔備份,存於互聯網檔案館)」, IEEE Transactions on Geoscience and Remote Sensing, Vol.47 (4), pp. 1156-1167, April 2009.

外部連結

[編輯]