Image Processing with Open Source Tools

My goal is to assemble an open source environment where I can prototype image processing algorithms in a fashion similar to Matlab. There’s two reasons for this. First, while Matlab is a great tool, it’s simply much too costly to obtain a commercial license for it. Especially in light of the fact that open source tools provide you with a high quality free alternative. Second, I’d like to make use of the  OpenCV computer vision and image processing library. For anyone not familiar with it, it’s a  high quality, high performant image processing and computer vision library maintained by the folks at  Willow Garage.

Here’s the list of tools that you need to install. If you are running Linux most will be available via your yum/apt-get programs.

1) Python + IPython

IPython is a python command line environment that gives you the Matlab-esque environment (e.g. tab-completion, history, etc.) It’s infinitely better than using a shell.

2) NumPy and SciPy Packages

These python packages give you access to Python’s numeric primitives like vector and matrix data types. You also get access to many numerical routines.

3) Matplotlib + PyLab

Matplotlib is a plotting library for Python. It comes with a module called PyLab which is a collection of commands that mimic Matlab. PyLab allows you to use many of the familiar Matlab commands to interact with data and generate plots (e.g. plot, imread, imshow, whos, etc.)

4) OpenCV + OpenCV Python Wrappers

At the heart of our image processing environment is the OpenCV package + Python wrappers which you can download here. This gives you access to image processing and computer vision algorithms for performing tasks such as feature detection, object tracking, classification, machine learning algorithms, etc.

Here’s a sample script that makes use of the OpenCV GoodFeaturesToTrack routine to detect interest points in an image. You can fire it off as a python script or run the “ipython -pylab” and type it in line by line.

[sourcecode language=”python”]
import cv
import numpy
from pylab import *

### adjust these parameters  ###
FILENAME = "books.jpg"

# Extract OpenCV good features to track
eig_image = cv.CreateMat(img.rows, img.cols, cv.CV_32FC1)
temp_image = cv.CreateMat(img.rows, img.cols, cv.CV_32FC1)
result = cv.GoodFeaturesToTrack(img, eig_image, temp_image, 500, 0.04, 1.0, useHarris = True)
imageHeight = img.rows

# Turn result into NumPy array ( Nx2 matrix of image coordinates )
p = numpy.array( result )

# Plot interest points…
plot( p[:,0], imageHeight – p[:,1], ‘ro’ )
imshow( imread( FILENAME ), origin="lower" )

The script above produces the following output:

Showing interest point detection output on an image of a bookcase

Leave a Reply

Your email address will not be published. Required fields are marked *