Setting up VLFeat with the Eclipse IDE on Ubuntu

  There didn’t seem to be any how-to on setting up VLFeat to work with a C/C++ IDE on linux that Googling threw up. After spending the better part of an hour (with multiple breaks for hair-tearing and ‘linux, Y U SO CRAZY’) trying to get things to work, it is fitting to put in the steps for future use, which turned out to be surprisingly simple but undocumented in a single place (especially when I forget and have to install it on a new system).


 Step 1

Download and unpack the VLFeat binary for linux. From now on, as given in the site, the location of the folder is referred to as VLFEATROOT.

 For having shell support, I followed the instructions in their website and added the following lines to the end of my .bashrc file. 

export PATH=VLFEATROOT/bin/glnx86:$PATH

Step 2:

Create a new C/C++ project in Eclipse and put in the following lines of code:

extern "C" {
#include <vl/generic.h>
} int main (int argc, const char * argv[]) {
VL_PRINT ("Hello world!") ;
return 0;

Step 3:

Make the following changes:

 Project -> Properties -> C/C++ Build 

Under the GCC C++ Compiler->Directories head, include the path VLFEATROOT (the -I {capital i} option).

Under GCC C++ Linker ->Libraries, add vl to the Libraries(-l {small el}) and VLFEATROOT/bin/glnx86 to the Library search path  (-L)


Step 4: entering the LD_LIBRARY_PATH in the Environment tab on the 
launch configuration (this caused the maximum hullabaloo)

Project -> Run As -> Run Configurations -> “Environment” tab

 Add an environment variable named LD_LIBRARY_PATH and set its value to the location of the file, which is VLFEATROOT/bin/glnx86. Make sure the option  “Append environment to native environment” is selected.


All done! 



Nothing works

Nothing works.

 No, that’s a lie. Let’s rephrase – everything (apparently) works other than what I’m interested in.
 Which is … wait for it … finding the medial-axis of an image at a single pass from the inverted Canny edgemap by computing the local maxima of its distance transform. 
 Head. Meet wall.
 I usually never refer to work – except as an euphemism for disaster – on this blog. This diversion may be mostly fueled by some random hope that ranting about it here might help. Somehow. 

Walking instead of hoping

Now more than ever I have stopped hoping, but started walking towards dreams.

There was a time not too long ago when I tried a dozen things and hoped they would work out. Rather, nowadays I do half -a-dozen and know  that they are working out. The metamorphosis from a lot of hot air and high-brow rhetoric to the present state of buckling down and getting things done did not happen in a day, nor was it painless.

Every person I believe needs one Ayn Randish “yes.” What I mean by that is at least one achievement that is fruitful and recognized. That one indication that you are treading the right path, even if that is the less trodden, that one vindication of your efforts when you are at the fag end of your fortitude.


And after that one confirmation the road doesn’t become less difficult, nor the study-hours less, nor the desire to hang out with dear friends any more nerve-sapping in the stark solitude of a lab, nor banging your head against a seemingly-thankless project any less frustrating.

But you get to know that there was a light in the tunnel. That there is a Promised Land, an Uttermost West (yes yes Tolkien to the end) or whatever: feel free to choose your favorite metaphor for the sum total of all aspirations.

It makes all the difference.

So here’s a big YES to each and every person trying to forge a path out of the mire of mediocrity, chasing dreams and persevering alone for the sake of a life less ordinary.

Eigenvalues of an image – OpenCV

OpenCV has great resources for beginners as well as for advanced users. But for those caught in the intermediate stage, you might call it an image processor’s angsty teenage years, there are little options other than scouring the messageboards and the helpful people at StackOverflow.

So I decided to address two issues that had held me up initially when starting out with OpenCV. The first one: converting an image (specifically a grayscale image) into a 2D array is something that comes naturally. Further operations at the pixel level become really simplified, the trade-off (as in everything) being some amount of computing efficiency. The second point is something that is directly related to my present project – that of computing the eigenvectors of an image.

I decided to punch both these concepts into a working function. All of this is self-evident really. Hopefully someone will waste less time than i did in a)figuring it out oneself or b)searching with Zen-like dedication until discovering someone else who did.

void calcEigen(IplImage* src) //input a 32 floating point image

	if(src->height != src->width)
		printf("\nDimensions must be same for eigen!!");
	int j,i;
	float **p;
	CvScalar se;

        //creating the 2D array - this part will work for unequal dimensions also
	p = (float**)malloc(src->height*sizeof(float*));
	for(i=0; i<src->height; i++)
		p[i] = (float*)malloc(src->width*sizeof(float));

	float *a;  //1D array reqd to convert IplImage to CvMat (grrrr)
	a = (float*)malloc( (src->height) * (src->width) * sizeof(float) );
	long int k=0;
	//image pixels into 2D array
	for(i = 0; i < src->height; ++i)
		for(j = 0; j <src->width; ++j)
			se = cvGet2D(src, i, j);
			p[i][j] = (float)se.val[0];


	//2D array into 1D array
	for(i = 0; i < src->height; ++i)
		for(j = 0; j <src->width; ++j)
			a[k++] = p[i][j];
	//1D datapoints into CvMat
	CvMat mat = cvMat(src->height,src->height,CV_32FC1, a); 
/*the resulting CvMat is used for many computations*/
		for(i = 0; i < src->height; ++i)
			for(j = 0; j <src->width; ++j)
				float t = (float)cvmGet(&mat,i,j); // Get M(i,j)
				//a[k++] = p[i][j];

/*Eigenvalue specific code begins*/
                CvScalar scal;
		CvMat* evec  = cvCreateMat(src->height,src->height,CV_32FC1); //eigenvectors
		CvMat* eval  = cvCreateMat(1,src->height,CV_32FC1);  //eigenvalues (1xN)
		cvEigenVV(&mat, evec, eval, 1);
			for( j = 0; j < eval->cols; j++ )
				/*access the obtained eigenvalues*/
                                scal = cvGet2D( eval, 0, j );
				printf( "\n%f\n", scal.val[0]);
		cvReleaseMat(&evec); //house-cleaning :P

Sucked into image processing

The project at CVPR unit over last winter was one of the best learning curves I ever had the benefit of traversing. The sheer independence and effort needed in learning something – an almost unknown topic – in a short span of time involved a lot of things. Things whose edge we tend to lose being cooped up in classrooms and curricula over time.

This was programming the way I liked it! This was the “thing” I had been missing for ages: the sheer joy of computing, of “leaving the machine as something more than what it was when you were first led up to it.”

The project itself was quite basic, something that a second year student of Information Technology would not have much trouble grasping. But the way linear algebra, statistics and wave-transforms all churn together in the pot-pourri of extracting text from outdoor scenes was well worth the effort (with the expectedly eccentric prof calling up at midnight about results).

Basically I have a student paper and a certificate to show at the end of the day, along with an advice to work again on the project this summer. Needless to say the last part was the thing that excites me the most.

Busy start to the year

The work at on Indic text detection in natural scenes is progressing fine. I started the project on 2 Jan and hope to complete it by mid-Feb.

My first experience in a research environment – and I honestly can’t get enough of it. Even given the fact that it’s a 2 hour bus ride from my place to the Stastical Institute. Using OpenCV and Visual C++ for the development. Not that geeky as to shun Microsoft when it’s useful: never believed in blind adherence or that sort of thing.

Now busy tweaking the  code to refine the results. It’s a huge relief to be done with the boiler-plate coding.

Plans for winter

The end sem routine was finally announced – a pretty spread out one from 8th to 22nd December. Which is great for me – i get to enjoy a sizable chunk of Christmas-time for a change. An old school buddy’s coming down to Kolkata after 3 yrs so more’s the reason to make merry I suppose.

Loads of things planned for the coming months, so let’s get started enumerating ’em

First and primarily (do we hear a triumphant crowing somewhere people :P)  there’s a decent chance of doing a project at the ISI, Kolkata. At the computer vision and pattern recognition unit. I’ll be going for the screening as soon as I’m done with exams. And keeping fingers eternally crossed.

There’s another project based training scheduled at CSI on DBMS which is confirmed. Keeping this one as a backup in case ISI doesn’t work out after all. Research based projects aren’t 9 to 5 IT jobs. If it stretches past my winter breaks commuting to college and from there to ISI (over an hour’s bus ride) and then back would require some serious time juggling.

Reading list over the vacations: SICP (hardcopy tee-hee), Essentials of Programming Languages, Intro to Algos – CLRS along with the video lectures.


After a long hiatus

Yes it’s been a while.

As projects go it’s been an eye-opener for me. Completed my first project summer this year – the ASP.NET stuff i’d mentioned at the Computer Society of India. Basically the final product minus frills turned out to be a functional website with a database used for polling results.

On the other hand, however commonplace be the project, we got the hang of using Visual Studio seriously. There nothing like meeting desperate deadlines to develop friendships, migraines and some serious coding.

Moving on to recent stuff, now that the mandatory flashback’s done and over with. Firstly, I joined the Rotaract Club in our college. It was really enjoyable working almost like a family rather than a team for a good purpose.

Secondly, I’m thinking hard about the Imagine Cup thing. Microsoft may be widely reviled by those with more academic inclinations, but the bottom line is this – MS technology still has a substantial chunk of users simply because its user-friendly and at the end of the day coding is coding. Got together a team. Let’s see how far we can go ahead with this.

Thirdly and most importantly … the algorithms course that I’ve decided to do independently. Data structures in our college is fine. I’m following Tanenbaum for that. Sometimes Aho, Ullman. For Algo I issued Cormen et al. from the British Council Library. Quite a tome! Then there’s this handy place near Jadavpur Uni which gives printouts for 50p. So i got hard copies of SCIP (yessss!) and another algo book by Dasgupta, Vazirani.

There’s still greater ease associated with reading a book in hard copy rather than in electronic format. Maybe it’s my age-old habit to annotate my textbooks and curl up on a couch while reading. It’s a habit i should break i guess. But at times the effort in overcoming it diverts me from the actual goal – reading the book. And trust me, that effort IS required when grappling with SICP or Introduction to Algorithms. 🙂

So, these Pujo vacations will be packed. I’m not going for the internship in Delhi after all. Will spend the time finding my depth in CS. Emphasis on data structures, algorithm analysis and SICP (at least the first few topics!). And C. Thoroughly.

Planning ahead

Things I have decided to do over this year:

Finish the  summer training in ASP.NET at Computer Society of India, Kolkata chapter. Which means I’ll have to go to College Street this afternoon and get a book – having missed two days (on a trip with school buddies) there’s a lot of catching up to do. Will  settle on Beginning ASP.NET 4 in C# and VB.

Next in line will be algorithms and data-structures. The latter will be given a thorough treatment in college lectures, however the former will require independent efforts. I’ve already earmarked a few e-books, will browse the college library once classes start.  Even now it’s easier to leaf through a physical tome rather than strain my eyes reading an e-book. Ah well.

A possible parallel foray into C# before August end, intend to gain sufficient proficiency by mid-November.

Re-aligning window controls in Ubuntu

Okay, so I’m not much into writing how-tos, mainly because most things have usually been written by the time I get around to ’em. However, a persistent grouse with Lucid Lynx was the unfamiliar grouping of window control buttons to the left of the pane.

The stuff was set aright in under a minute.

gconf-editor at the terminal.
At the configuration editor window that comes up, browsed to the Apps ->metcity ->general and then changed the button-layout value in the right pane.
It goes something like maximise, minimise, close:
The colon demarcates the alignment. So, simply putting the control names to the right of the colon made things back to normal. 🙂