2011-01-11 61 views
11

任何人都可以告訴我如何使用RANSAC算法來選擇兩個圖像中具有特定重疊部分的共同特徵點?問題是從基於特徵的圖像拼接中產生的。
alt text alt textRANSAC算法

+0

你的問題太含糊。重疊角落意味着什麼? – koan 2011-01-11 09:06:43

回答

20

我實現了一個圖像拼接幾年回來。維基百科上的RANSAC文章很好地描述了一般的algortihm。

當使用RANSAC進行基於特徵的圖像匹配時,您想要找到將第一幅圖像轉換爲第二幅圖像的變換。這將是維基百科文章中描述的模型。

如果您已經獲得了兩張圖片的特徵,並且發現第一張圖片中的哪些特徵與第二張圖片中的哪些特徵最匹配,則可以使用RANSAC。

The input to the algorithm is: 
n - the number of random points to pick every iteration in order to create the transform. I chose n = 3 in my implementation. 
k - the number of iterations to run 
t - the threshold for the square distance for a point to be considered as a match 
d - the number of points that need to be matched for the transform to be valid 
image1_points and image2_points - two arrays of the same size with points. Assumes that image1_points[x] is best mapped to image2_points[x] accodring to the computed features. 

best_model = null 
best_error = Inf 
for i = 0:k 
    rand_indices = n random integers from 0:num_points 
    base_points = image1_points[rand_indices] 
    input_points = image2_points[rand_indices] 
    maybe_model = find best transform from input_points -> base_points 

    consensus_set = 0 
    total_error = 0 
    for i = 0:num_points 
    error = square distance of the difference between image2_points[i] transformed by maybe_model and image1_points[i] 
    if error < t 
     consensus_set += 1 
     total_error += error 

    if consensus_set > d && total_error < best_error 
    best_model = maybe_model 
    best_error = total_error 

最終結果是將image2中的點最佳轉換爲image1的轉換,這在拼接時非常實用。