📄 readme
字号:
Demo code for detecting and matching SIFT features -------------------------------------------------- David Lowe (lowe@cs.ubc.ca) Version 4, July 6, 2005This directory contains compiled binary programs for finding SIFTinvariant features that can run under Linux or Windows. In addition,there is a Matlab script as well as C source code showing how to loadthe features and do simple feature matching.See the web page at http://www.cs.ubc.ca/~lowe/keypoints/ for references to the relevant papers describing this approach.Running from within Matlab--------------------------If you have access to Matlab, scripts are provided for loading SIFTfeatures and finding matches between images. These were tested underMatlab Version 7 and do not require the image processing toolbox.Run Matlab in the current directory and execute the followingcommands. The "sift" command calls the appropriate binary to extractSIFT features (under Linux or Windows) and returns them in matrixform. Use "showkeys" to display the keypoints superimposed on theimage: [image, descrips, locs] = sift('scene.pgm'); showkeys(image, locs);The "match" command is given two image file names. It extracts SIFTfeatures from each image, matches the features between the two images,and displays the results. match('scene.pgm','book.pgm');The result shows the two input images next to each other, with linesconnecting the matching locations. Most of the matches should becorrect (as can be roughly judged by the fact that they select thecorrect object in a cluttered image), but there will be a few falseoutliers that could be removed by enforcing viewpoint consistencyconstraints.You can also try matching other images: match('scene.pgm','box.pgm'); match('scene.pgm','basmati.pgm');For more details, see the comments in the Matlab scripts: sift.m,showkeys.m, and match.m.Acknowledgments: The Matlab script for loading SIFT features is basedon one provided by D. Alvaro and J.J. Guerrero.Binaries for detecting SIFT features------------------------------------You do not need Matlab to run the demo. The program binary forkeypoint extraction under Linux is named "sift", and should run undermost versions of Linux on Intel compatible processors. The executablefor Windows is named "siftWin32.exe". The code was developed underLinux and follows Unix conventions, but the Windows binary producesidentical keypoints.You can detect keypoints and display them on the provided test imageswith the command line option "-display" as follows (for Linux):% sift -display <book.pgm >result.pgm[If you are using Windows, first open the Windows Command Prompt andcd to the directory containing the binary before executing thecommand. In all cases when using Windows, replace sift withsiftWin32.]This will write out a new image, result.pgm, with arrows overlayedindicating the locations, scales, and orientations of the keyfeatures. You can inspect this image using the public domain program xv:% xv result.pgmor use any other tool that displays the common PGM image format. [Under Windows, you can use the freeware program IrfanView (www.irfanview.com)to view PGM images and covert to/from other formats.]Note that you can control the number of keypoints by scaling the imageresolution. An image of size 500 pixels square will typically giveover 1000 keypoints depending on image content, which is plenty formost applications. Images from most digital cameras should be greatlyreduced in resolution before being used. Changing image resolution isthe best method to control the number of keypoints, as it is thelarger scale keypoints that are most reliable and this is also muchmore efficient than processing large images. The current compiledbinaries will raise an exception for images with dimensions greaterthan about 1800 pixels in any dimension. Color images will need tobe convereted to grayscale (PGM format is only for grayscale images).ASCII file output for keypoints-------------------------------Without any command line arguments, the "keypoint" program willoutput the keypoints in a simple ASCII file format thatis convenient to read by other programs and provides the data neededfor matching keypoints:% sift <book.pgm >book.keyThe file format starts with 2 integers giving the total number ofkeypoints and the length of the descriptor vector for each keypoint(128). Then the location of each keypoint in the image is specified by4 floating point numbers giving subpixel row and column location,scale, and orientation (in radians from -PI to PI). Obviously, thesenumbers are not invariant to viewpoint, but can be used in laterstages of processing to check for geometric consistency among matches.Finally, the invariant descriptor vector for the keypoint is given asa list of 128 integers in range [0,255]. Keypoints from a new imagecan be matched to those from previous images by simply looking for thedescriptor vector with closest Euclidean distance among all vectorsfrom previous images.Example of image matching using keypoints-----------------------------------------To demonstrate the value of the keypoints for image matching, thisdirectory also contains some simple C source code to read keypoints from2 images and show the best matches between the images with lines drawnon top of the images connecting the matching locations. The code iswritten for Linux, although it should not be difficult to port to Windows.The matches are identified by finding the 2 nearest neighbors of eachkeypoint from the first image among those in the second image, andonly accepting a match if the distance to the closest neighbor is lessthan 0.6 of that to the second closest neighbor. The threshold of 0.6can be adjusted up to select more matches or down to select only themost reliable. See my research papers for the justification behindthis approach.First, create keypoints for each test image:% sift <book.pgm >book.key% sift <scene.pgm >scene.keyTo compile the matching code in this directory under Linux, simply do:% make[No makefile is given for Windows, although the code is quite portableand should be fairly easy to compile under Windows.]This will create a demo program called "match". This programrequires command line arguments giving each of the two images andtheir corresponding keypoints:% match -im1 book.pgm -k1 book.key -im2 scene.pgm -k2 scene.key > out.pgmThe resulting image in "out.pgm" contains the first image above thesecond one, with white lines connecting the matching locations. Mostof the matches should be correct (as can be roughly judged by the factthat they select the correct object in a cluttered image), but therewill be a few false outliers that could be removed by enforcingviewpoint consistency constraints. You can inspect the matchingresults with xv:% xv out.pgmYou can also try the results for the other objects in the scene:% sift <box.pgm >box.key% match -im1 box.pgm -k1 box.key -im2 scene.pgm -k2 scene.key > out.pgm% sift <basmati.pgm >basmati.key% match -im1 basmati.pgm -k1 basmati.key -im2 scene.pgm -k2 scene.key > out.pgmYou should be able to run this demo program to find matches betweenany pair of images in PGM format. Of course, this matching approachis overly simple, and many more correct matches could be found byusing a higher distance threshold and enforcing viewpoint consistencyconstraints between the set of resulting matches to eliminateoutliers, as described in my research papers.Licensing conditions--------------------This software is being made available for research purposes only. Itis necessary to obtain a license from the University of BritishColumbia for commercial applications. See the file LICENSE in thisdirectory for conditions of use.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -