Wednesday, October 6, 2010

Converting VLFeat SIFT output to Lowe-compatible SIFT output for Bundler

I've recently been trying to get Bundler working on my Mac. Bundler is a part of a set of software (also including PMVS, CMVS, and others) that provides an open-source alternative to Microsoft PhotoSynth. Unfortunately, it has a dependency on a closed-source implementation of the SIFT keypoint-detection algorithm written by David Lowe.

There are a few open-source implementations of the SIFT algorithm, and one is part of the VLFeat toolkit. Unfortunately, VLFeat's SIFT tool generates differently formatted output from the Lowe version, even though it's the same sort of information. I spent far too long hunting for a conversion script, and found no standalone (or even Bundler-ready) one, so I did it with awk.

If you are using Bundler, you can just update the ToSift.sh script, replacing the line:

echo "mogrify -format pgm $IMAGE_DIR/$d; $SIFT < $pgm_file > $key_file; rm $pgm_file; gzip -f $key_file"

with


echo "wc -l $key_file.vlfeat | awk '{ print \$1 \" 128\" }' > $key_file"
echo "awk 'BEGIN { split(\"4 24 44 64 84 104 124 132\", offsets); } { i1 = 0; tmp = \$1; \$1 = \$2; \$2 = tmp; for (i=1; i<9; i++) { i2 = offsets[i]; out = \"\"; for (j=i1+1; j<=i2; j++) { if (j != i1+1) { out = out \" \" echo "rm $key_file.vlfeat"


Once that's done, the RunBundler.sh script can be run as usual.

If you'd rather just convert existing VLFeat-generated key files, you can use:

zcat vlfeat.key.gz | wc -l | awk '{ print $1 " 128" }' > lowe.key

zcat vlfeat.key.gz | awk 'BEGIN { split("4 24 44 64 84 104 124 132", offsets); } { i1 = 0; tmp = $1; $1 = $2; $2 = tmp; for (i=1; i<9; i++) { i2 = offsets[i]; out = ""; for (j=i1+1; j<=i2; j++) { if (j != i1+1) { out = out " " }; out = out $j }; i1 = i2; print out } }' >> lowe.key
gzip lowe.key


Hope this helps someone avoid the effort!

Tuesday, February 2, 2010

Stop Muni service cuts

This is a repost of an email I sent to Mayor Newsom to encourage him to avoid Muni service cuts. For more information on the issue, see the SF Bike Coalition's take, or the official Muni page.

Dear Mayor Newsom:

I usually agree with your policies, which is why your stance on Muni is so jarring to me. When I moved to San Francisco, I gave up my car, assuming correctly that I'd be able to get everywhere by bike and transit. Cutbacks in Muni services feel like a betrayal of trust -- will I have to start waking up earlier to get to work on time? Am I going to be effectively trapped on home on weekends when the weather is bad?

Especially in bad weather, I ride Muni almost every day. I take the 22 to and from BART so I can get to work, and on weekends, I often take the 19 to shopping downtown. (The bus is such a better option than driving that I'll often push my roommates with cars to ride the bus instead of trying to park when we go to the Metreon for movies.) I visit friends in Cole Valley by taking the N.

You've expressed concern that increasing parking hours and prices will drive down visits to businesses, but from what I've read, the MTA's plan is not likely to result in the same disaster that occurred in Oakland. My roommates, who drive, never express concern about the prices of parking being too high. Rather, they complain about the lack of parking spaces, an issue which higher rates might actually improve!

In addition, although the following is not written by me, I thoroughly agree with all it has to say:

I am writing to urge you to find a way to make Muni work-- the proposed service cuts are unacceptable for a Transit First city. The proposal to reduce frequency will throw Muni into a downward spiral-- with riders unable to depend on regular service, people will stop riding Muni and driving more, creating more traffic, pollution, and reducing service even more.

Any service cuts must be off the table-- and I urge you to find alternative ways to fund Muni. We are a Transit First city and funding Muni must be your top priority. With the potential for millions of dollars by strategically extending parking meter hours, you can save Muni.

Private auto traffic congestion is the top reason for Muni delays-- and free, unabated parking encourages driving while starving the Muni budget. It is essential that you, as a 'green' mayor and leader of this Transit First city, support your appointee's approval of the recommendations of MTA Staff to extend meter hours into the evening and Sunday in specific commercial corridors.