## Tuesday, 12 March 2013

### Playing around with OpenCV and Complex Functions

Last week my college hosted a technical fest. It was pretty cool. There was some really cool tech on display at for the exhibitions, some awesome guest lectures, robotics competitions and a lot of workshops. It was quite a busy and interesting week. I attended this really interesting workshop that introduced us to image processing using Matlab. We managed to get matlab to track a ball in the field of view of my laptop's webcam and use this motion to control windows media player and the movement of wheeled bots. Recently, I've become really interested in the field of Artificial Intelligence so this simple computer vision exercise got me excited. I came back to my room that evening and started exploring my options.

That evening I discovered an excellent Open Source alternative for doing image processing called OpenCV. I decided to abandon Matlab and do image processing in OpenCV instead (Because it's freeeeeeee!). That very evening I got OpenCV compiled and set up on my Ubuntu partition and started learning image processing.

I had a bit of difficulty starting out because I'd never really learnt C++ 'officially'. So I had to use my basic knowledge of C and a lot of googling to understand the basics of setting things up. The biggest hurdle was understanding how classes and objects worked. It took a few hours to smooth those concepts out. As soon as I had a rudimentary grasp of what they meant I could start writing my first image processing program.

So fooled around with flipping and adding noise to images for the last week. Then I got a brilliant idea. I was having a bit of trouble visualizing what I was learning in math class. We were doing conformal maps. So I thought that it might be a good idea to use OpenCV to visualize conformal maps. So I set out trying to apply conformal maps to Lenna,  one of the most famous test images used in image processing.

It took me a couple of days to make the code completely bug free. There were some really annoying bugs. The fact that images were stored in matrices whose indices followed a left handed coordinate system added to the difficulty of implementation. I had to apply multiple transformations in series to get the code to work. But in end everything came together and this was the result!

 The result of applying the transformation $w = z^{2}$.
Right now, the only transformation that works perfectly is $w = z^{2}$. Other functions give really weird outputs. I'll figure them out eventually.

And I've decided to open source the code I used for this! It's very messy because it's not the final version of the code and it's full of commented code and random cout statements.  But maybe somebody will find it useful.

The code can be found here: http://pastebin.com/kBBP2ASe