Languages for image processing

Over the years I have written image processing (and computer vision) algorithms in a number of languages – from C, to Matlab, and now Python. C is obviously the fastest of the pack, but in the early years before the advent of OpenCV in 2000 suffered from a lack of consistent and robust libraries. Sure, you could write them yourself, however when you’re dealing with trying to solve a problem, the last thing you really want to do is write standard libraries. C also suffers from a syntax which is not that amenable to complete array operations, unlike languages such as Python, and even Fortran. For example, there is no simple way of modifying the saturation component of the HSI colour space (Hue-Saturation-Intensity). In Python the code to modify saturation by taking a power of 0.65 would look like this (where imgS is the saturation component):

imgS = imgS**0.65

In C the same code would look like this:

for (i=0; i<nRows; i=i+1)
    for (j=0; j<nColumns; j=j+1)
        imgS[i][j] = pow(imgS[i][j],0.65);

Not grievously more code, but in a large, complex algorithm, this can become quite tedious. Python also provides a large number of built-in functions to deal with arrays, especially with the use of Numpy. OpenCV solves some of these issues, and provides data structures and I/O to deal with images. Standard C makes a mess of images, because large ones are required to be stored using dynamic arrays, or more likely dynamic structures, as size information can then be coupled with the array itself. But whilst Python provides easy-to-write code, it suffers from a lack of efficiency (I’ll talk about that some more in a future post). Sure, Python can be efficient, if you are good at vectorization (but it can be a steep learning curve). C trumps most languages with the ability to efficiently process things. There is a solution of course. Use Python for ease of use, and couple it with C functions for the grunt work.

I also used Matlab for many years, and IDL before that. When you didn’t have time to re-invent the wheel, before OpenCV, these options were great. But Matlab is expensive, and it doesn’t make stand-alone programs easy to develop. I have tinkered a bit with Julia too, but it may be too early for serious image processing. In the end, a language that makes manipulation of arrays easy is ideal – from processing without the need for a nested loop, to extracting a sub-image with a single line of code.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s