Internship at Metalworks – Week 10 [17 August to 20 August 2015]

My penultimate week at Metalworks has ended and I have many thoughts about my internship which I will share next week. Meanwhile, I’m leaving for Japan in 2 weeks and have just started research with my computer science professor on model analysis and verification. I’ll speak more about that in another post, but this week at Metalworks was about touching up on my work on image processing and running some debugs.

Monday – Thursday: Running debugs / touching up on code

Image Processing

This was the structure of my code:

for x in range(len(p)):
for y in range(len(p[0])):
do: <insert task>

Having two for loops is disastrous for run-times in a Raspberry Pi. Even on a Pi 2, it took a good 15 seconds to process – not good enough for the project I was working on. Thus, we threw that out of the window. Instead, we eventually settled for a much much simpler option, which was using the image editor already embedded in the Pi. GraphicsMagick did the trick in less than 2 seconds on the Pi 2, which really makes me wonder how it did it so quickly. The command was really just this: gm convert -modulate <brightness, saturation> <input filename> <output filename>. Jay and I thought it must be multithreading, using multiple processors in the CPU to do the job. Or perhaps they used C++ and pointers to loop through a bitmap instead of an array. I will have no idea as of this time. I tried looping through the image bitwise, but that proved to be too long compared to GraphicsMagick. Incredible, it reduced the code to just one line – the power of libraries.

But that also left me with lesser flexibility to do what I really wanted with the image, which was to enhance contrast given a certain criteria, but while we are at prototyping phase, sometimes we can settle for a little less.


One of the features we tried to implement was when one function was being run by the CPU, could we run another process simultaneously and break the foreground process when necessary?

That brought us to multithreading, which was a whole new world for me altogether. In my algorithms and data structures class, we briefly touched on the topic of parallel programming, but I had no idea how to access this topic. Well, I’ll leave that for another time, but if you want to know a little more about it, a quick google search brought me here (quora), here (stackoverflow) and here (of course wikipedia). I still don’t understand it fully, but I will eventually get there once I’ve learnt enough in class.

Eventually, we used another method to create the same effect we wanted, which was just about killing processes (less elegant, but does the job – sounds like a prototype??)

Raspberry Pi / Command Line

I admit. I do not have enough experience with command line work, and I’m often made to look very amateurish when it comes to doing things efficiently. It is really about the little things like “cd ~/<insert filename in root folder>” or “sftp pi@<insert IP address>” that is the difference between a seasoned user and someone who just flops around on Google searching for command line shortcuts.

And I guess, that concludes the reflections for this week! There really wasn’t much as the rest was touching up on the projects and doing rounds of testing and debugging and pushing code. Watch out for my post early next week on the beginnings of my research.

That’s it from me!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s