Life is a game, take it seriously

Posts Tagged ‘SURF feature point’

SURFmex bugs

In Computer Vision, Matlab on May 8, 2011 at 9:46 am

written by Gooly

Continuing the last post, I have to mention some bugs in SURFmex that needed to be noticed.

First, be aware of the orientation the SURFPOINTS function give back. It is in a counter clockwise direction, however if you try to plot on Matlab, the column row axis is in the clockwise direction; it is easy to get confused and have the wrong direction. Actually this is one of the mistakes in the surfplot function given by SURFmex under the common folder. Another bug is the degree to radian problem, be aware that the SURFPOINTS function gives the orientation in degree; the surfplot function uses it assuming it is radian instead. Change the surfplot function as follows to correct the bugs.

function surfplot(points,info)

    colorline= {'r-','b-','c-','g-','m-'};
    phi = linspace(0,2*pi);
    x = cos(pi/2 + phi);
    y = sin(pi/2 + phi);
    bbox = [x 0; y 0];

    for k = 1:size(points,2)
        scale = info(1,k);
        ori   = -info(3,k)*pi/180;

        R = [cos(ori) -sin(ori);sin(ori) cos(ori)];

        pbox = scale*R*bbox + points(:,k)*ones(1,size(bbox,2));
        hold on;
        plot(pbox(1,:),pbox(2,:),colorline{mod(k,5)+1});
    end
end

Another bug is an OpenCV bug, an error would occur if you input a pretty flat image which it couldn’t find any interest points. A work around of this is to check if it’s a flat image before calling SURFPOINTS, since if it’s a flat image, you probably wouldn’t want to match it; or you can do a histogram equalization before calling SURFPOINTS, this would solve the problem.

SURF On Images: continue

In Computer Vision, Matlab on May 7, 2011 at 11:43 pm

written by Gooly


Continuing the last post, I will show how to actually work on SURF points using MATLAB. First download the SURFmex library; this is a second version released in 2008, which is simply a wrapper around the OpenCV dll. The good thing about OpenCV is that it’s open source and actively used, so you won’t get stuck in a dll which couldn’t move to another OS. Note that you have to fix the surfplot function bug in the common folder, see this explanation. Next, put the library in the project folder and remember to right click on it and add to path. Now, put 2 images, in my case img1.png and img2.png, in the same folder. Next step, download a small function I wrote to show the matching result like the image above from here (or search match_plot on Matlab Central); put the function in the same folder. Finally, add the following code and run.

function match_test()

close all;
clear;

% surfnum = 1:30;

left_img  = imread('./img1.png');
right_img = imread('./img2.png');

[spixels_l,descr_l,sign_l,info_l] = SurfPoints(rgb2gray(left_img));

figure;
imshow(left_img);
hold on;
plot(spixels_l(1,:),spixels_l(2,:),'r*'); hold on

[spixels_r,descr_r,sign_r,info_r] = SurfPoints(rgb2gray(right_img));

figure;
imshow(right_img);
hold on;
plot(spixels_r(1,:),spixels_r(2,:),'r*'); hold on

matches = surfmatch(descr_l,descr_r);

surfnum = randi(size(matches,2),1,30);

match_plot(left_img,right_img,spixels_l(:,matches(1,surfnum))',spixels_r(:,matches(2,surfnum))');

figure;
imshow(left_img);
hold on;
surfplot(spixels_l(:,matches(1,surfnum)),info_l(:,matches(1,surfnum)));

figure;
imshow(right_img);
hold on;
surfplot(spixels_r(:,matches(2,surfnum)),info_r(:,matches(2,surfnum)));

end

You will get 2 image which have all of the SURF points marked, and an image like the one above which matches 30 random SURF points, and 2 images showing the orientation and size of the SURF points like the image below.

On the next post, I’ll show how to do simple object recognition using SURF points. By the way, if you work on stereo vision, these images must look familiar; for those who don’t know, search for middlebury 

SURF On Images: feature point matching

In Computer Vision, Matlab on April 25, 2011 at 4:06 pm

written by Gooly

SURF (Speed Up Robust Features) is a scale and rotation invariant interest point detector and descriptor. It could be categorized under the family tree of the widely used SIFT feature. These SIFT like features are commonly used in various applications such as stereo vision, object recognition, image stitching since the 21th century. One good example is the famous Microsoft project “ Build Rome in a day“.

The feature finding process is usually composed of 2 steps; first, find the interest points in the image which might contain meaningful structures; this is usually done by comparing the Difference of Gaussian (DoG) in each location in the image under different scales. A major orientation is also calculated when a point is considered a feature point. The second step is to construct the scale invariant descriptor on each interest point found in the previous step. To achieve rotation invariant, we align a rectangle to the major orientation. The size of the rectangle is proportional to the scale where the interest point is detected. The rectangle is then cropped into a 4 by 4 grid. Different informations such as gradient or absolute value of gradient are then subtracted from each of these sub square and composed into the interest point descriptor.

The SURF feature is a speed up version of SIFT, which uses an approximated DoG and the integral image trick. The integral image method is very similar to the method used in the famous Viola and Jones’ adaboost face detector.  An integral image, despite its pretty name, is just an image which its each pixel value is the sum of all the original pixel values left and above it. The advantage of integral image is that after an image is computed into an integral image, it can compute block subtraction between any 2 blocks with just 6 calculations. With this advantage, finding SURF features could be several order faster than the traditional SIFT features.

SIFT like features have become quite a basic component in general computer vision courses, and also a good point to start some vision research. There is no need to reinvent the wheel, since there are various libraries online for free. OpenCV has both SIFT and SURF libraries. However, since Intel abandoned the project, the 2.x series is poorly documented and lack books to study. Fortunately, there are other choices for Matlab users. The VLFeat vision library provides a nice SIFT library and a simple tutorialSURFmex also provides an interface from Matlab to the OpenCV SURF library. I will show how SURFmex could be used in the following posts.