File Exchange

image thumbnail

SIFT Feature Extreaction

version (11.4 KB) by Xing Di
This is the feature extraction by SIFT


Updated 02 May 2015

View License

This MATLAB code is the feature extraction by using SIFT algorithm. Just download the code and run. Then you can get the feature and the descriptor. Note, If you want to make more adaptive result. Please change the factories: row, column, level, threshold., and d(in the last part). For other factories, please do not change until you understand David G. Lowe's paper and my code.

Cite As

Xing Di (2020). SIFT Feature Extreaction (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (68)

If i change the number of octaves to 4 and the number of levels to 5, keypoints are only found in the top-left quarter of the image. Can anyone suggest why this may be happening?

Yiran Wang

asd asd

weng chi

ebraheem ka

Shuai Guo

Elsa kazemi

hello . Thanks for your sharing codes.
I work with not necessarily square images. I work with grayscale images with different width and height. I've been testing your codes and gives me error:

Error in siftme (line 95)

what is keypoint in a image? How keypoints are identified?

Can You please tell the process of image feature extraction and I want to detect image forgery using SIFT....

The keypoint coordinates are here:
%x,y centeral point and prepare for location rotation

Some of them are discarded in the code so you just need to keep the final one that are used to build the features vector.

Qin Xu

The code needs very long time to execute. I have not get the result for an image. It seems that the number of the points is very large obtained by this code. Why the size of image must resize to 256×256?

S. Sahar

Hi, Can anyone please tell me how can i calculate the coordinates of features?

Anyone know how to extract the coordinates of the detected feature points, please?

Hi Marco, could you share the piece of code you used to extract coordinates.

scale = sigma0*sqrt(2)^(1/level)^((i-1)*level+j);

What is the meaning of this line?
Can anyone explain me about this? or show me about equation?

I figured it out: a keypoint has multiple orientations, hence of course features' vector contains also multiple descriptors for each keypoint. I was able to extract coordinates. Anyway Xing Di the matching algorithm doesn't work properly for different rotation. Could you suggest me how to solve this problem? Descriptors are not able to be invariant to rotations, despite you used the keypoints' orientation for that purpose.

Anyone was able to obtain the keypoints xy coordinates? I tried to extract them from rx, rx but I got a different number of keypoints compared to the features' size.


isha patel

error: creation of arrays greater than this limit may take a long time and cause matlab to become unresponsive.
which size of image is required?

lei chen

I get good results by using your code,thanks.Do you have the code for matching the feature between two images?

Dajie Wang

dega wong

i'll try it later


Never mind :) Figured it out.


Trying to download this file. It is not a .m file. It is an HTML file. Am I missing something? There is no Matlab code in this file. Only HTML.

Nidheesh N

Hi Xing, I compared your code with Lowe's original code. It is seen that there is difference in the number of descriptors(features) returned for a 256x256 greyscale image. I tried with a few images. I got different numbers in each case. Your code returns a relatively high number of descriptors. Why is it so?

Cheng Ning



Ginish V

By using this code for the 1st image the feature is 50*128 and for the 2nd image feature is 40*128. feature dimensions are different for both the images then how will we match these two images.

mukemmel olmus elinize kolunuza sağlık...super perfect health in your hand selim

when defining x coordinates in image in the procedure of keypoint localisation, first octave fully loop around but range of x coordinates start to decrease proportionally since second loop. is x=ceil(j/n) appropriate?

Why number of extrema compute on this way?

for i=2:octave+1 number=number+(2^(i-octave)*colum)*(2*row)*interval;

Liming Xu

A typo in Title 'Extreaction' should be 'Extraction'. :)



Hao Pang


i am unable to understand the last steps of coding.
what is done over here.
and please help me to understand keypoint discriptor section's coding.

I want to detect eye using harris corner and SIFT how can I do it?

Gauri sahu


If I am not wrong, in this code in order to create DoG images in each octave, rather than subtracting two subsequent Gaussian Images(e.g.Dog2 = 3-2, Dog1 = 2-1),the subtraction is done with reference of original image in each octave(eg. Dog1 = 1-original,DoG2 = 2-original, DoG3 = 3-original), which is different from the paper, in which I guess two subsequent images are suggested. Does It make any difference on the overall performance of the algorithm?

fanar Ali

Okay, now I get the descriptor vector for all keypoints which is the feature vector as you said. However, I still have a problem identifying the xy coordinates of the keypoints that correspond to the descriptors in the feature vector.


Hi, Xing Di
Thanks for your sharing codes.
I interest in the difference of Gaussian which is the first step of SIFT. there is a question confused me how to compute the scale parameter. The scale parameter is computed firstly, but before computing the second octave, the image is drop sampled. Therefore, the scale is changed. is it right that the scale parameter need to multiply 2?


I put in a 500x374 RGB jpg, and the script took 2.5 hours to run with Matlab 2015a on a system that has an i5-4570 and 8 gb of RAM. Any idea why it's so slow?

Thanks for sharing, very good.

Dear Xing Di,
How can i extract
spatial locations of keypoints? can u please suggest


Please I have one questions:
why the number of features is very high for an image.
In Sift (Scale Invariant Feature Transform) Algorithm inspired this file the number of descriptors is small - maybe 1800 vs 183599 in your code.
If I use 256 * 256 dimension my compute is hanging.


Hi Xing Di,

Thank you for sharing the codes.

I have the same questions with aazz, how could I know the matrix tells the coordinates of all the keypoints that corresponds to the descriptors in the feature vector?

Thank you

Shuang Gao

Hi Xing Di,

In code block of "accurate keypoint localization", it uses secondorder_y only to calculate one direction derivatives and then locate the local extrema location. Based on my current understanding of the paper, shall we solve a linear system (with secondorder_x and secondorder_y) to get the location?

I hope this will help me

aazz nn

Hi Xing Di,

Thanks for replying.

Okay, now I get the descriptor vector for all keypoints which is the feature vector as you said. However, I still have a problem identifying the xy coordinates of the keypoints that correspond to the descriptors in the feature vector.

May I know which matrix tells the coordinates of all the keypoints that corresponds to the descriptors in the feature vector?

Xing Di

aazz, I am sorry for a confusion in my code, the variable "descriptor" is the one certain point's descriptor,and the variable "feature" is the descriptors for the whole keypoints

aazz nn

Hi Xing Di,

I am a newcomer to SIFT. I have a set of images which varies only in terms of scale. I ran your code to detect the keypoints and it is fine. However, I noticed that there are more keypoints than descriptors calculated. From my understanding, there should be equal number of keypoints and descriptors for a given image in order to match the keypoints in that image with a translated version of that image.

My question is how can I match the keypoints in the image which does not have equal number of descriptor and keypoint with another image?

Xing Di

Lester, I am very sorry. I really want to help you to solve the problem. However, I really do not understand what happened, because I really do not meet the error on my own. please try the renew one. If it does not work yet, I hope you can understand the SIFT algorithm based on the paper and my code. Then, you can write the one by yourself. Or, if you have any problem, you can contact with me with the email address in the code.

I downloaded the new version. I work with not necessarily square images. I work with grayscale images with different width and height. My initial code is like this:

% row = 256;
% colum = 256;
img = imread ('v41.jpg');
[row, colum, plane] = size (img);
if plane == 3
     img = rgb2gray (img);
% img = imresize (img, [row, colum]);
% img = rgb2gray (img);
and then the whole process of SIFT. Note that v41.jpg can be any size.
This time the code give me the error:
Matrix dimensions must agree.
Error in ==> SIFT_feature at 137
         . D {i} (:,:, j) = temp * CONV2 (test ', [- 1, -1, 1.1],' same ') * 0.5 + test;

Its implementation is very compatible with David Lowe algorithm and is the most comprehensive I've seen in Matlab. It would be helpful for me to use your implementation of SIFT in not square images. Greetings.

Xing Di

Dear Lester Oropesa, actually, this is a mistake in my code. now, i have fixed it. you have two options to do, first, download my renew code. second, exchange "/m" and "/n", because when we want to know the x label, we need to use the total to divide column length instead of row length. you can fix by your own. However, if it is not work, I recommend you download the renew one.

Hello appreciable Xing Di. I've been testing your version of david lowe algorithm and gives me error on line 81

??? Index excede matrix dimensions.

Error in ==> SIFT_feature at 81
             sub = {D i} (ceil (j / m): ceil (j / m) + 2 mod (j-1, n) +1: mod (j-1, n) + 3, k-1: k +1);

I noticed that for different values of 256x256 row and colum the alforitmo fails.
row = 480;
colum = 640;

You know how I can correct this error?
Greetings. Lester

Lian Wang

Very Good!

Very good

Jingwan Fu

Very good! Keep going!

Xing Di

this is my first work!

Xing Di

Perfect! You re genius!


Note: descriptor is a certain keypoint's descriptor, and feature is the total descriptor for the whole points

descriptor mistake correct, and more clear comment to understand.

small mistake correct

result image update

mistake change

Thanks to Lester Oropesa for the mistake finding If you guys have download the code and do not want to re-download. please exchange the "/m" ("./m") with "/n"("./n"). If it does not work, please re-download. Sorry for the inconvenience.

1. mistake Correct
2. speedup program

Sorry for the inconvenience, This time this code is correct.
Note: If you download the last edition. The orientation assignment part is not correct. the keypoints location part is all right. I really recommend you update it to this edition

there is one mistake in the last update, I have corrected it. Sorry for the inconvenience.

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux