SiftGPU (Cg/GLSL/CUDA) for Matlab

Categories:
computer vision
Tags:
cuda, gpu, i hate matlab, matlab, sift, source code

Changchang Wu has a beautiful implementation of David Lowe’s scale invariant feature transform (SIFT) inspired by Andrea Vedaldi’s sift++ and Sudipta N Sinha et al’s GPU-SIFT. Adam Chapman has also made a MATLAB mex version which will allow you to pass in the filename of an image and retrieve the SIFT descriptors and keys as well as perform the matching. If that sounds like a lot of people have implemented this algorithm, then check this out.

I had tried using Adam Chapman’s version though, unfortunately, I already had my images loaded into the MATLAB workspace after performing some manipulations and didn’t want to keep writing/reading from disk, thinking that it would be a waste of computation time. I was also processing a lot of images in turn and was running into a lot of crashes, perhaps from continually loading and unloading the library? I haven’t seen anyone complain about this version on the mathworks site, so maybe it is just me.

In finding a way to avoid writing and reading to disk, I did not foresee a problem in the way MATLAB and OpenGL handle their image data. After a brief exchange with Changchang Wu, he led me on to the problem of needing the data in row major as opposed to column major format. As it turns out, the overhead of converting the image to row major is slightly worse than writing and reading the image to disk (at least for an 800×600 with jpeg compression) with the SiftGPU library. Though, there is probably a better way of doing this than in MATLAB, (like most tasks).

Not all is lost though (I could have been sleeping!), I slipped in another simple extension of Adam Chapman’s build which will allow you to keep the SiftGPU library loaded in memory and process as many images as you like without fear of crashing (or is it just me?). I’ve also included a demo app which shows how to do this for a grayscale and rgb image and shows the results in timing on a few different ways of finding the sift features. It also includes V340 of the SiftGPU library which will let you do matching on the GPU!

You can download it here.

[update 25/10/10]:  you can get an updated download with the yasift files here.

To run, first compile:

>> mex -setup
>> mex -c yasift.cpp
>> mex yasift.cpp

Now try out the demos:

>> yasiftdemo
>> yasiftmatchdemo

The general idea is to first open or initialize the library by doing:

>> yasift(‘open’)

Then you can set the parameters like so (check out Adam Chapmans .doc file for possible settings):

>> yasift({‘e’, ’10’, ….})

Now you are ready to process any images:

>> img = imread(‘frame0.jpg’);
>> [desc keys] = yasift(img);
>> [desc keys] = yasift(‘frame1.jpg’);
>> [desc keys] = yasift(‘frame2.jpg’);
>> [desc keys] = yasift(‘frame3.jpg’);

You can also do matching by passing in two images at once:

>> img1 = imread(‘frame0.jpg’);
>> img2 = imread(‘frame1.jpg’);
>> [desc1 keys1 desc2 keys2 matches] = yasift(img1, img2);

When you are done, unload the library:

>> yasift(‘destroy’)

I sometimes find that the actual mex file is still in memory and can be cleared with a clear all command.

Hope it works for you