83

I've recently come across a problem which requires at least a basic degree of image processing, can I do this in Python, and if so, with what?

1

8 Answers 8

53

The best-known library is PIL. However if you are simply doing basic manipulation, you are probably better off with the Python bindings for ImageMagick, which will be a good deal more efficient than writing the transforms in Python.

Sign up to request clarification or add additional context in comments.

3 Comments

I think you have that backward: PIL provides only the absolute most basic barebones functionality, but it does integrate nicely to Python GUIs. IM is tremendously more full-featured but requires some manual work trading buffers back and forth to integrate with a GUI.
Let's put it this way, sad but PIL seams to be abandon-ware and it doesn't even load BMP files created with Paint. If you check project web-page you'll figure it out, look for bug tracker (none), mailing list activity, SCM, ...
Pillow is a fork of PIL that is being maintained and developed. It's probably better to use it instead.
46

Depending on what you mean by "image processing", a better choice might be in the numpy based libraries: mahotas, scikits.image, or scipy.ndimage. All of these work based on numpy arrays, so you can mix and match functions from one library and another.

I started the website http://pythonvision.org which has more information on these.

4 Comments

"The scikits.image SciKit (toolkit for SciPy) extends scipy.ndimage to provide a versatile set of image processing routines." I wonder why they didn't just contribute directly to ndimage.
All these packages have different internal structures. At least my package, mahotas, took a lot of code from ndimage, though.
scikit-image is now hosted at scikit-image.org
scipy.ndimage link is dead. Current link, most probably: scipy.github.io/devdocs/tutorial/ndimage.html
19

You also have an approach to image processing based on "standard" scientific modules: SciPy has a whole package dedicated to image processing: scipy.ndimage. Scipy is in effect the standard general numerical calculations package; it is based on the de facto standard array-manipulation module NumPy: images can also be manipulated as array of numbers. As for image display, Matplotlib (also part of the "science trilogy") makes displaying images quite simple.

SciPy is still actively maintained, so it's a good investment for the future. Furthermore, SciPy currently runs with Python 3 too, while the Python Imaging Library (PIL) does not.

4 Comments

For future reference, ndimage requires PIL anyway.
@notJim: does it? PIL is not listed in the dependencies of SciPy by MacPorts, and I can do import scipy with no PIL install (import Image fails with ImportError).
Yes, when I tried to read an image using ImRead, I got the error “raise ImportError("Could not import the Python Imaging Library (PIL)"”
@notJim: It is true that SciPy relies on PIL for image reading (I tried with a "simple" JPEG file, and it failed in the same was as in your example). SciPy can still do image processing without PIL (PIL is an optional dependency).
11

To complete the list: opencv http://opencv.willowgarage.com/documentation/python/index.html

1 Comment

OpenCV is now at opencv.org
7

There's also pycairo, which might be more suitable depending on your needs.

Comments

6

There is actually a wonderful Python Imaging Library (PIL). It gives you the ability to alter existing images, including anti-aliasing capabilities, and create new images with text and such. You can also find a decent introductory tutorial in the PIL handbook provided on the aforementioned site.

4 Comments

Did you use Google at all before asking this question? :-) I'm not saying that you should, just that it seems a bit funny to answer your own question in less than a minute.
The whole idea of this site is to provide (question,answer) pairs which will serve as useful information for someone searching on the subject. It is encouraged that if you find out something useful you did not know before, and it isn't already on the site, that you share it with StackOverflow.
From the FAQ: It's also perfectly fine to ask and answer your own programming question, but pretend you're on Jeopardy: phrase it in the form of a question. Although, I think this question could easily be answered by anyone in need quickly through a google search...
@MartinW - I found this question via google search
4

If you are creating a custom image processing effect, you may find PythonPixels useful. http://halfhourhacks.blogspot.com/2008/03/pythonpixels.html It is intended for writing and experimenting with image processing.

Comments

3

VIPS should be fast and uses multiple CPUs:

https://github.com/libvips/libvips/wiki/Speed-and-memory-use

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.