尺度不變特徵變換(SIFT算法)Matlab程序代碼測試例子的說明(Lowe的代碼)

原鏈接http://hi.baidu.com/simonyuee/item/0c91a6b8e8cd61a4ebba936a

目前網絡上可以找到的關於SIFT算法Matlab測試代碼的資源就是:

1 加拿大University of British Columbia 大學計算機科學系教授 David G. Lowe發表於2004年Int Journal of Computer Vision,2(60):91-110的那篇標題爲“Distivtive Image Features from Scale -Invariant Keypoints" 的論文。作者在其學術網站上發表的Matlab程序代碼(注意,這個程序代碼的初始版本是 D. Alvaro and J.J. Guerrero, 來自Universidad de Zaragoza。)

    上述代碼可以很容易檢索到,如,http://www.cs.ubc.ca/~lowe/keypoints/

2 美國加州大學洛杉磯分校(University of California at Los Angeles) Andrea Vedaldi 博士研究生給出的基於David Lowe 發表的論文給利用Matlab和C語言混合編程給出的Sift detector and descriptor的實現過程。

      http://vision.ucla.edu/~vedaldi/

    

Andrea VedaldiPh.D. Candidate / VisionLab / UCLA face Andrea Vedaldi () Boelter Hall 3811 (Vision Lab - map) University of California, LA (UCLA) (formerly University of Padova DII - map
Résumé. 
News
  • 4/10/2008 - Minor tweaks to the MATLAB/SIFT code to eliminate dependencies on LAPACK (easier to compile)
  • 25/1/2008 - VLFeat new version and website.
  • 1/11/2007 - VicinalBoost code is now available.
Bio. Andrea Vedaldi was born in Verona, Italy, in 1979. He received the DIng from the University of Padova, Italy, in 2003 and the MSc in Computer Science (CS) from the University of California, Los Angles (UCLA) in 2005. He is the recepient of the UCLA 2005 outstanding master in CS award and he is currently enrolled in the UCLA Ph.D program.Popular code Collaborators
  • Stefano Soatto, University of California at Los Angeles, Los Angeles, USA.
  • Serge Belongie, University of California at San Diego, San Diego, USA.
  • Paolo Favaro, Heriot-Watt University, Riccarton, Edinburgh, UK.
  • Hailin Jin, Adobe System Incorporated, California, USA.
  • Andrew Rabinowich, University of California at San Diego, San Diego, USA.
  • Gregorio Guidi, University of California at Los Angeles, Los Angeles, USA.
  • Brian Fulkerson, University of California at Los Angeles, Los Angeles, USA.

3 以後陸續有許多基於Sift算法實現圖像目標匹配和目標識別等方面的應用,大多都是基於上述的代碼和算法原理來進行的。

關於第一測試代碼的說明:

1 共有三段Matlab代碼源文件

   match.m:測試程序

     功能:該函數讀入兩幅(灰度)圖像,找出各自的 SIFT 特徵, 並顯示兩連接兩幅圖像中被匹配的特徵點(關鍵特徵點(the matched keypoints)直線(將對應特徵點進行連接)。判斷匹配的準則是匹配距離小於distRatio倍於下一個最近匹配的距離( A match is accepted only if its distance is less than distRatio times the distance to the second closest match.
                該程序返回顯示的匹配對的數量。( It returns the number of matches displayed.)

    調用實例: match('desk.jpg','book.jpg');

        ( 假如,想測試一個含有一本書的桌面的圖像 和一本書的圖像之間特徵匹配)

     調用方法和參數描述:略。

     注意:(1)圖像爲灰度圖像,如果是彩色圖像,應該在調用前利用rgb2gray轉換爲灰度圖像。

                 (2)參數distRatio 爲控制匹配點數量的係數,這裏取 0.6,該參數決定了匹配點的數量,在Match.m文件中調整該參數,獲得最合適的匹配點數量。

   sift.m :尺度不變特徵變換(SIFT算法)的核心算法程序

     具體原理詳見David G. Lowe發表於2004年Int Journal of Computer Vision,2(60):91-110的那篇標題爲“Distivtive Image Features from Scale -Invariant Keypoints" 的論文

     功能:該函數讀入灰度圖像,返回SIFT 特徵關鍵點( SIFT keypoints.)
  

 調用方法和參數描述:

  調用方式:[image, descriptors, locs] = sift(imageFile)

  輸入參數( Input parameters):

    imageFile: 圖像文件名.

     輸出或返回參數( Returned):
       image: 是具有double format格式的圖像矩陣
      descriptors: 一個 K-by-128 的矩陣x, 其中每行是針對找到的K個關鍵特徵點(the K keypoints)  的不變量描述子. 這個描述子(descriptor)是一個擁有128個數值並歸一化爲單位長度向量.
       locs: 是K-by-4 矩陣, 其中的每一行具有四個數值,表示關鍵點位置信息 (在圖像中的行座標,列座標(row, column) ,注意,一般圖像的左上角爲座標原點), 尺度scale,高斯尺度空間的參數,其中該參數也決定了frame(結構)確定的圖像disk的大小, 最後一個參數是方向orientation). 方向參數的範圍是[-PI, PI] 單位爲弧度.
%

    

    appendimages.m:    該函數創建一個新的圖像分別包含兩個匹配的圖像和他們之間的匹配對的連接直線.

2、測試結果

  輸入圖像1:book1gray.jpg

   輸入圖像2:book2gray.jpg

運行結果1:(比例參數爲0.6 )

調用過程: match('book1gray.jpg','book2gray.jpg')

輸出結果:
Finding keypoints... 
394 keypoints found.   (第1幅圖像中檢測到394個特徵點)
Finding keypoints... 
488 keypoints found. (第2幅圖像中檢測到488個特徵點)
Found 82 matches.  (找到了82個匹配點)

ans =

    82

運行結果2:(比例參數爲0 . 5 )

調用過程: match('book1gray.jpg','book2gray.jpg')

輸出結果:
Finding keypoints... 
394 keypoints found.   (第1幅圖像中檢測到394個特徵點)
Finding keypoints... 
488 keypoints found. (第2幅圖像中檢測到488個特徵點)

Found 55 matches.  (找到了55個匹配點)

運行結果3 把第二個測試圖像變成其中的一個局部,如圖 (book2graypart.jpg)

參數同上,比例參數爲0 . 5 

調用過程: match('book1gray.jpg','book2graypart.jpg')

Finding keypoints... 
394 keypoints found. 
Finding keypoints... 
121 keypoints found. 
Found 26 matches.

ans =

    26

1 在Matlab環境調用主函數

match('book1gray.jpg','book2gray.jpg')

2 注意,必須使matlab 的當前工作文件夾設置成你當前的文件夾


3 這個match 中,增加了 shoukeys的調用,可以顯示每個圖像全部的關鍵特徵點矢量信息。


回覆hrr1109:

1 關於匹配點的像素座標

參考源程序文檔被Match.m調用的Sift.m,其調用格式爲

[image, descriptors, locs] = sift(imageFile),

所以,在Match.m中最前面返回的Locs參數就保留了進行匹配的兩個圖像所以的特徵點的座標信息:

(locs: K-by-4 matrix, in which each row has the 4 values for a keypoint location (row, column, scale, orientation). The orientation is in the range [-PI, PI] radians.)

   你可以在Match.m源程序中,在最後找到匹配點聯線的循環語句:

for i = 1: size(des1,1)
if (match(i) > 0)
    line([loc1(i,2) loc2(match(i),2)+cols1], ...
         [loc1(i,1) loc2(match(i),1)], 'Color', 'c');
end
end

凡是Match數組不爲零的,其下表i 和本身的值match(i) 就是對應的結果信息(索引座標數組的)。

2 關於Matlab文件保存

請參考: Matlab中的保存數據語句比較

http://blog.sina.com.cn/s/blog_4ec6e1720100g0ss


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章