Python: A Powerhouse for Image Processing

Python: A Powerhouse for Image Processing

NumPy, as we discussed recently, is vital to a lot of artificial intelligence software, but its power has also propelled Python into a related software niche: image processing.

What Image Processing Is

Image processing refers to using software to either extract information from an image or to manipulate or change the image. Examples of the former include tasks like counting the number of objects in an image or computing the area of a given object or region of interest (ROI) in the image. Examples of the latter include accurately converting an image’s color space from RGB (for display on a screen) to CMYK (for printing), increasing an image’s contrast,  and applying software corrections to an image in order to cancel out an optical aberration (like barrel distortion or vignetting).

Image processing has a lot of overlap with computer vision, one of the AI technologies we mentioned in our previous series. Just like the Python AI software we mentioned then, NumPy is fundamental to Python image processing software, as we’ll see below.

Even though images are reducible to grids of numbers, what we often do to them can be mathematically and computationally complex. Sometimes, we want to all the objects of a certain shape in an image. Other times, we want to identify the edge of complex shapes or remove noise or distortion from an image.

Simple data, meet powerful math. Just as in AI, NumPy is the foundation for much of the image processing software available to Python developers. In fact, Python is the current king of hill when it comes to languages for image processing.

Python vs. IDL

But it wasn’t always this way. IDL, a language currently owned and controlled by Harris Geospatial, had long been the language of choice for image processing and analysis among astronomers and others.

The compelling benefits of Python, together with it’s rapid adoption, has stormed the last strongholds of IDL. In fact, one of the key highlights of one of the latests releases of IDL is a Python bridge, allowing IDL developers to call Python code from IDL and vice versa.

With the bridge in place, let’s meet the army rushing across it.

Scikit-image is a module which includes implementations of many image processing algorithms in Python. It is actively developed, and like Python itself is open source and free to use. Scikit-image processes images by first importing those images as NumPy arrays. Scikit-image also interfaces with other image processing software, like OpenCV.

Pillow is a fork of the Python Imaging Library (PIL). Unlike PIL, however, Pillow is still actively maintained, as evidenced by the commit history on its GitHub page. Unlike Scikit-image, Pillow doesn’t require NumPy nor operates on NumPy arrays, although one can easily convert between NumPy arrays and Pillow images.

Those two are probably the most popular and powerful modules for image processing in Python, but there are others, notably Mahotas, PythonMagick, and pycairo. This group tends to be more limited in scope (pycairo, for example, just provides Python bindings to a 2D graphics library), but can be very useful it they’re just the type of specialized tool you need.

From scientific and statistical analysis of images to manipulation and display, Python developers have access to an extensive armory of image processing software.

Copyright © Python People