SIFT(Scale-Invariant Feature Transform)是計算機視覺里程碑式算法,實現圖像特徵的尺度、旋轉、光照不變性匹配。本文系統梳理五大步驟、尺度空間/DoG金字塔數學建模、特徵描述子生成、匹配策略,並給出Lowe開源實現關鍵函數接口解析。





L(x,y,σ) = G(x,y,σ) * I(x,y)
G(x,y,σ) = 1/(2πσ²) exp(-(x²+y²)/(2σ²))
同一物體在不同尺度下表現不同,需多尺度檢測。
D(x,y,σ) = L(x,y,kσ) - L(x,y,σ) ≈ (k-1)σ² ∇²G
計算簡單,無需二階導數,尺度歸一化後極值點對應LoG極值點。
k = 2^{1/s}(s為每組層數,通常s=3)。s+3層高斯圖,產生s+2層DoG圖,可在s層中檢測極值(需上下層比較)。
3×3×3鄰域比較,保留局部極大/極小值。x̂,|x̂|>0.5則拋棄。r = Tr²/Det,r > (γ+1)²/γ(γ=10)視為邊緣點拋棄。1.5σ圓域收集梯度幅值/方向。σ=1.5σ)。4×4子區,每區8方向直方圖 → 4×4×8=128維向量。
int sift_features(IplImage* img, struct feature** feat);
// 返回特徵點數,feat輸出特徵點數組(需調用者釋放)
// 內部調用 _sift_features 並傳入默認參數
int _sift_features(
IplImage* img, struct feature** feat,
int intvls, // 每組層數 s,默認3
double sigma, // 基礎高斯σ,默認1.6
double contr_thr, // 對比度閾值,默認0.04
int curv_thr, // 邊緣曲率閾值,默認10
int img_dbl, // 是否預先放大2倍,默認1
int descr_width, // 描述子子區寬度,默認4
int descr_hist_bins // 方向bin數,默認8
);
int _sift_features(...) {
IplImage* init_img = ...; // 預處理/放大
IplImage*** gauss_pyr = build_gauss_pyr(init_img, ...);
IplImage*** dog_pyr = build_dog_pyr(gauss_pyr, ...);
CvSeq* features = detect_extrema(dog_pyr, ...); // 3D極值檢測
features = refine_features(features, ...); // 泰勒定位+閾值篩選
assign_orientations(features, gauss_pyr, ...); // 主方向分配
compute_descriptors(features, gauss_pyr, ...); // 128維描述子
*feat = features_to_array(features); // 輸出
return feature_count;
}
cv::SIFT::create()(non-free模塊)、cv::ORB::create()一鍵調用。SIFT 將差分高斯金字塔、極值檢測、方向直方圖、梯度描述子四大模塊有機融合,構建了經得起時間考驗的局部特徵標準。理解其數學本質與工程細節,是計算機視覺進階的必修課。