Image Processing, In Python? [closed]
Asked Answered
M

8

82

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?

Migrate answered 18/9, 2008 at 17:47 Comment(1)
Realtime image processing using PyPy: morepypy.blogspot.com/2011/07/…Edgy
P
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.

Playboy answered 18/9, 2008 at 17:54 Comment(3)
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.Complication
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, ...Inguinal
Pillow is a fork of PIL that is being maintained and developed. It's probably better to use it instead.Scorper
S
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.

Saddlery answered 22/4, 2011 at 21:11 Comment(4)
"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.Fairweather
All these packages have different internal structures. At least my package, mahotas, took a lot of code from ndimage, though.Saddlery
scikit-image is now hosted at scikit-image.orgStrawberry
scipy.ndimage link is dead. Current link, most probably: scipy.github.io/devdocs/tutorial/ndimage.htmlPicul
A
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.

Albritton answered 5/5, 2010 at 9:19 Comment(4)
For future reference, ndimage requires PIL anyway.Gist
@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).Albritton
Yes, when I tried to read an image using ImRead, I got the error “raise ImportError("Could not import the Python Imaging Library (PIL)"”Gist
@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).Albritton
E
11

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

Envision answered 28/9, 2011 at 5:43 Comment(1)
OpenCV is now at opencv.orgHouseclean
G
7

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

Giess answered 29/11, 2009 at 8:53 Comment(0)
M
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.

Migrate answered 18/9, 2008 at 17:47 Comment(4)
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.Adriatic
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.Migrate
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...Rosaline
@MartinW - I found this question via google searchEdgeways
I
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.

Insessorial answered 19/9, 2008 at 5:39 Comment(0)
A
3

VIPS should be fast and uses multiple CPUs:

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

Astral answered 10/10, 2011 at 10:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.