Tuesday, May 11, 2010

The magic of ImageMagick

I haven't posted anything here in a while. The main reason is that I am still trying to get used to the idea of blogging. There is so much crap on the internet, I want my posts to be of value not only to myself but also to the occasional surfer who might stumble upon my blog. Earlier today I read a news story on BBC that we will soon be running of available IPv4 addresses. I suspect that if we start a "crap cleaning" initiative and then somehow sustain it, we may not need to worry about running out of space for a while. But of course, many will take issue with this since one man's crap is another man's treasure.

Anyways... I was faced with the problem of creating zoomed insets for a paper. In my first naive attempt, I used an image editing software (gimp to be exact) to tackle the problem. What was the problem with that? I had to deal with many annoying point and click operations. No fun at all. Then I thought about using ImageMagick. After a few attempts at the command line, this is what I came up with:


convert image.bmp -resize 600x390 \
\( image.bmp -crop 230x110+240+240 -bordercolor black -border 1x1 \) \
-gravity NorthEast -composite \
\( image.bmp -gravity NorthWest -crop 150x80+220+540 -bordercolor black \
-border 1x1 \) -gravity SouthEast -composite \
-fill none -stroke black -draw "rectangle 120,120 235,175" \
-draw "rectangle 110,270 185,310" \
image_small.bmp


Here is an example of what can be achieved with this one-liner.



The insets come from the original high resolution image image.bmp, and are specified by cropping a rectangular region. The working stack provided by ImageMagick comes in really handy for this purpose. Finally, the images are composited and rectangles are drawn in the appropriate locations.

Wednesday, August 19, 2009

A day with Rogers' HTC Magic

My 3-year term with Bell Mobility will be up soon. With all the buzz about smartphones, I thought I'd get an early start and try out Google's android. In Canada, there are currently two choices, both with Rogers: the HTC Dream and the HTC Magic. The Dream is rather bulky because of its QWERTY keyboard and is an older model as compared to the more compact Magic. Since I would be stuck with the company for a while, I thought it would be more appropriate to go for the latest product.

There are many reviews out there of the HTC Magic, so I will focus on those aspects that are important to me, i.e. multimedia, podcasting and GPS capabilities.

In a nutshell, here is my impression of the device. Google has designed a very nice mobile OS and I really like the idea of a notification bar. However, the hardware of the HTC Magic is just not beefy enough to deliver the android goodness. If you want more details, read on.

What I really liked:
  • The moment I powered on the device, it asked me to sign into my Google account. It then automatically setup my contacts, gmail and calendar. A big plus for sure.
  • Three screens of widgets and a wallpaper that stretches across the three screens. If you like desktop widgets, you will certainly like this platform. There are a few built in widgets such as a clock, calendar and weather. Although I did not try, I am sure there are more available in the android marketplace.
What I really did not like:
  • The interface is very laggy, the touch screen keyboard is very hard to use in portrait mode and the bottom edge of the screen seems to be less sensitive than the rest of the screen. This makes typing a really frustrating experience. There is no multi-touch.
  • Video playback simply sucks! Although, the specifications say that the device can play mp4 files, most of the ones I tried refused to play. The ones that did play lacked the sharpness and fluidity that is found on the iPods or the Creative portable media players.
  • The 3.2 MP camera takes ok still pics. However, the video recorder is just not acceptable. The videos are really low res and the audio is recorded at a really low bit rate.
  • There is no built-in support for podcasts. However, there are a number of third party podcatching applications available in the marketplace. The one I tried seemed to be a really capable application. It gave me the option of managing all the podcasts directly from the phone, no need to sync with a computer. However, because of the subpar video playback capabilities, most video podcasts I subscribe to, did not play.
  • GPS seemed to have a mind of its own. It would not automatically update the location unless I pressed the 'My Location' button. The locations almost always seemed to be off by a couple of blocks. I tried to use it in downtown Vancouver, North Burnaby and Surrey.
  • The device also seems to be very buggy. Applications seemed to be crashing a lot making the device even more sluggish. I found myself occasionally restarting it, so that it would be usable again.
After about a day's use, I had had enough of the device. No wonder Rogers has reduced the price down to $49.99. The very next morning, I went back to the store and returned it. It's a good thing that the contract had a 15 day return policy.

In my opinion, most of the problems associated with the device are really hardware related. Perhaps the HTC Hero, if it is released in Canada, will iron out the kinks. I really would like to see android taking up a fare share of the smartphone market as it seems to be a very capable OS. For now, however, I suppose we are better off with the Blackberry, iPhone or even Windows Mobile.

Monday, August 3, 2009

Celebration of Light 2009


Finale, originally uploaded by ankahi.

I took this photo from Burnaby Mountain Park near SFU. China was scheduled to put on its fireworks show as part of the Celebration of Lights 2009 (at English Bay in Vancouver, BC) festival. It was 10 pm at night and mosquitoes were feeding on my feet :( Needless to say, I was quite distracted. Still, I think I managed to get a couple of nice shots. There wasn't much visible to the naked eye but I could clearly see the skyline through the camera's eye (a Canon 100-300mm f/4.5-5.6 USM lens set at max zoom).

Tuesday, May 12, 2009

The price of WYSIWYG

Last week, I worked quite a bit in LaTeX. It is surely the way to go if you want to write a technical paper and sometimes I wonder why I shied away from it for such a long time. It produces high quality documents and has extensive support for typesetting mathematical formulas. One of the things that has bugged me is the lack of WYSIWYG for mathematical content. You have to compile your source files to see what the formulas are going to look like. Or do you?

If you are an emacs user like me, waste no time and start using (if you already aren't) AUCTEX. There are a few things you have to learn to get up to speed but the returns are phenomenal. You no longer need to compile the entire document, you can simply preview it within Emacs, all figures and mathematical formulas get rendered right inside the emacs buffer. I almost went through a whole day of typing without compiling the source. The preview feature is simply amazing.

Another thing I worked on was a presentation, and lo and behold, I prepared it in LaTeX using beamer. I spent almost two hours trying to work through WYSIWYG annoyances in Apple's Keynote and eventually gave up. Here are some of the things that bugged the crap out of me.

  • I don't like to use the mouse to align content, it's just not the right approach. I should be able to type at a meta level, simplify specify what type of content I am working on and the software should take care of the alignment and the formatting.
  • Keynote has a nice feature that you can simply cut out formulas from an existing PDF and paste them onto your slides. They retain their vectorized representation! However, if you need to resize things, it's just so hard to ensure that everything remains consistent.
  • When there is a lot of content, the mouse just becomes an obstacle. In emacs, I can just focus on typing up my content, both the actual presentation content and the meta information such as formatting, themes, colors etc. I rarely need to use the mouse, things just flow along nicely. Try doing that in Keynote or Powerpoint.

Monday, May 4, 2009

Bow to the Maestro

So, I am fortunate to have had the opportunity to listen to the ghazal maestro, Jagjit Singh. The concert was held in Queen Elizabeth theatre, he sang in front of a full house, some 3000 people. The stage was very nicely decorated with little oil lamps spread across, two big projection screens displayed artwork at changed according to the mood of the song being played.. so did the lighting.

The first half was mostly dedicated to ghazals but I was somewhat disappointed as he did not sing my favorite Mirza Ghalib (مرزا غالب) ghazal "Dil hi to hai (دل ہی تو ہے)". Perhaps it would have been a little too heavy for the crowd as the major portion seemed to be Punjabi speaking.
The live renditions were also dinstinctly different from the versions you hear on recorded albums. There was usually a lot of emphasis placed on the first verse of a couplet to build up anticipation for the second verse. This is actually quite typical of Urdu poetry readings. However, it is somewhat inconvenient when one already knows the ghazal.

The second half was devoted to requests and since the crowd was mostly Punjabi, I wasn't surprised that most of the songs were Punjabi. The tempo also built up from soft and mellow to loud and more Bhangra like. I wasn't expecting this at all as I know Jagjit solely as a ghazal singer.
On the whole, it was quite a memorable experience and I would definitely see him again if I have the chance.

Impression or Deception

While we are talking about Consulates, I thought it would be appropriate to mention my experience of visiting the Consulate General of Pakistan in Vancouver.

The consulate is located on the 14th floor of a modern building in downtown Vancouver. A high speed elevator took us to the 14th floor. When I got there, I felt I was in the wrong place. I was expecting to be greeted in Urdu by an old bearded brown man. Instead, we were received by a young oriental girl who spoke in a clear Canadian accent. We explained the purpose of our visit and she guided us to the consular office. During the short hop between the reception desk and the office, I happened to glance around a bit. The place was as plush as a five star hotel lobby; wall to wall carpeting, shiny desks made of some really good quality wood and spotless windows that made the scenic vistas of the waterfront area even more appealing.

Overwhelmed by the poshness of the consulate, I reluctantly opened the door to the consular room. Inside, there was a sparkling mahogany desk in a corner and some chairs were neatly arranged facing the desk. Behind the desk was a big color portrait of Jinnah mounted on a wall. Photos of the picturesque northern mountains adorned the other walls of the room. Moments later, a Pakistani guy walked into the room and took care of our paperwork. His attitude had a kind of politeness that you wouldn't find in any government office in Pakistan!

Now, the picture of Pakistan that they are trying to paint is poles apart from what Pakistan is really like. Government offices are dilapidated with termite infested furniture and waterlogged walls. When I left the office, I couldn't help but wonder... what are they trying to prove? Are they trying to impress overseas Pakistanis so that they would think about moving back, or are they trying to beguile westerners who have no idea what the third world is like? Whatever the case maybe, I walked out with a strange but positive mood tinged with nostalgia and hope. Perhaps one day, Pakistan will be like its consulates abroad.

Friday, May 1, 2009

Consulates, Consulates, Consulates!

My visa escapades took me to three Consulates this week, the Canadian consulate in Seattle and the French and Pakistani consulates in Vancouver. Sounds like I have the typical symptoms of "Traveling while Pakistani", a condition that my motherland gave me. I actually visited the Canadian consulate a couple of weeks ago, they approved our visas but but owing to a newly instituted regulation, asked me to come back after a waiting period of 10 days. Anyhow, the purpose of this post is to talk about the first impressions that one would get by visiting these consulates and dealing with the people there.

The Canadian consulate in Seattle is located on the 6th floor of an office tower in downtown Seattle. There is an old security guard who makes you pass your bags through a screening machine and then walk through a metal detector. When you emerge on the other side, you are required to take a number and then wait for your turn. The space is clearly designed to help people obtain visit visas as the procedure seems to be streamlined for that. Everything works in a systematic way and there are helpful instructions clearly posted so that one does not get lost. Every now and then, they make announcements telling people what processing stage the applications are in so that the distraught applicants can breathe a sigh of relief. The officers are courteous and take their time to answer inquiries. All in all, I would say that this is a good example of WYSIWYG. Whatever expectations one would develop after visiting the consulate, Canada would certainly live up to them, if not exceed them. I can safely claim that since I have been living in Canada for over three years.

The French consulate was a different cup of tea. The consulate is also in an office tower but the similarities pretty much end there. The office is locked behind large opaque doors that open when someone from the inside decides that it's OK to let you in. There was a buzzer beside the door, I pressed it and a person speaking French greeted me:

"Bonjour! Consulat Général De France".

I responded in English saying that I had an appointment.. and then there was deafening silence, for a whole 10 seconds! I got a bit nervous and asked,

"Excuse me, is the door open?"

The same person responded, this time in English with a thick French accent.

"But I don't know oo you are".

Was he waiting the whole time for me to give him my name. Wasn't he supposed to ask me in the first place?

Anyhow, I gave him my name and he let me in. Nervously, I entered the office. There were two windows to my right, behind one was an old security guard who I had spoken to on the buzzer. Behind the other was a middle-aged blond woman. I approached the security guard and slipped him the appointment letter. He glanced over it, then stared at me and stuck his right palm up with his elbow resting on the desk, and uttered one word.

"Document!"

I actually had a whole slew of documents, I wasn't sure which document he was asking for. I thought the most logical choice would be the visa application form, so I slipped him that. He pulled it in, looked over it and then stared back into my face. His palm was still up, I figured he wanted more documents so I decided to proceed in order hoping that he would make his intentions clear using words.

"Here is my itinerary."

Nothing! No words at all, did he not speak English, I wondered? No, that couldn't be as he had spoken to me on the buzzer. The palm stayed up, the eyes kept staring into my face. I gave him one more document but alas, that didn't change anything. So I pulled out the whole stack of documents and handed it all to him and said,

"OK, that's all the documents, I don't have anymore".

Finally he uttered some words,

"Non, that's not all, what's meeseeing"?

In all my nervousness, I had actually forgotten to give him the most important document, my passport. I gave him that and the ordeal was finally over. The palm went down and he asked me to have a seat in the waiting area. I collected my wits and wondered if the actual interview would be this grueling. To my surprise and relief, the rest of the process was pretty smooth sailing. The blond lady in the other window interviewed me. She was quite pleasant and more than made up for the security guard's attitude.

Now, I can't help but wonder why he reacted the way he did. Does he behave like that with everyone? Was it some sort of French humor which I failed to perceive? Whatever it was, it definitely left a sour taste. I hope the rest of French bureaucracy isn't like him. Let's see what's in store for me, I should be finding out about the visa in a few days.