[CS] scale-unchanged feature transform matching algorithm SIFT
Scale Invariant Feature Transform matching algorithm SIFT
E-mail: chentravelling@163.com
SIFT Algorithm
The SIFT algorithm is Scale-invariant feature transform. This article does not describe the principle of this algorithm, if you want to understand the principles, refer to another detailed CSDN article (Click here to view). This article describes more details. The SIFT algorithm consists of five steps: (1) create a scale space and detect the extreme points of an image: Create a scale space using the Gaussian differential function, and use the Gaussian difference scale-space (DoG scale-space) detects the local extreme points of an image. (2) Remove unstable points and determine the key points: unstable points are mainly the key points of unstable edge points and low contrast, Dacid G. lowe uses the method of fitting second-order differential equations to eliminate low-contrast points, and the Harris corner detection method can be used to remove unstable edge points. (3) determine the direction of the key point: the main principle is to count all Gradient Direction histograms in the key point field, and use the maximum value in the Histogram as the main direction of the key point. In addition, to improve the robustness of subsequent matching, take the direction in which the peak value in the histogram exceeds 80% of the main peak as the secondary direction of the key point. (4) extract key point Descriptor (5) Key Point Matching: only the Euclidean distance between feature vectors is used to evaluate the degree of similarity between key points. A preset threshold is used for filtering. The threshold setting directly affects the number and accuracy of matching points. The general threshold value is 0.7 ~ In the range of 0.8. To better see the effect of the SIFT algorithm, you can practice it.C ++ codeEnvironment: vs2010 + opencv2.3.1 + win7 × 64
#include
#include
using namespace std;using namespace cv;int main(){//read the two input imagesMat image1 = imread(image1.jpg);Mat image2 = imread(image2.jpg);//if failedif(image1.empty()||image2.empty()){cout<
keypoint1,keypoint2;//detect image with SIFT,get key pointssiftDetector.detect(image1,keypoint1);Mat outImage1;//draw key points at the out image and show to the userdrawKeypoints(image1,keypoint1,outImage1,Scalar(255,0,0));imshow(original_image1,image1);imshow(sift_image1,outImage1);Mat outImage2;siftDetector.detect(image2,keypoint2);drawKeypoints(image2,keypoint2,outImage2,Scalar(255,0,0));imshow(sift_image2.jpg,outImage2);//imwrite(sift_result2.jpg,outImage2);//store 10 keypoints in order to watch the effect clearlyvector
keypoint3,keypoint4;for(int i=0;i<10;i++){keypoint3.push_back(keypoint1[i]);keypoint4.push_back(keypoint2[i]);}// difine a sift descriptor extractorSiftDescriptorExtractor extractor;//store the descriptor of each imageMat descriptor1,descriptor2;BruteForceMatcher
> matcher;vector
matches;Mat img_matches;//compute the descriptor of each imageextractor.compute(image1,keypoint3,descriptor1);extractor.compute(image2,keypoint4,descriptor2);//matchmatcher.match(descriptor1,descriptor2,matches);//show the resultdrawMatches(image1,keypoint3,image2,keypoint4,matches,img_matches,Scalar(255,0,0));imshow(matches,img_matches);//store the match_image//imwrite(matches.jpg,img_matches);waitKey(0);return 0;}
Running EffectIn sequence: The Source image. After the source image is sift, the original image is scaled and rotated, and then sift.
In order to clearly see the relationship between matching points, the program selects 10 key points from the SIFT key points of each graph and 10 points corresponding to the subscript, theoretically, there may be some problems, that is, these points are not actually matched points, so this may be the cause of incorrect matching results. If we match all the key points, the effect is as follows:
In sequence, the source image matches the source image and the scaled image, and the original image matches the scaled image.
The two matching images also show that there is an incorrect match.