Python for image processing

Given how much Python is brought up, I would like to give it a try as well. I have dabbled in it in the past but that was long ago. For the purposes of image processing on win7 using python, which setup and packages would you employ?

1 Like

I have not actually done Python image processing, but what about something like the Python Imaging Library (PIL)?
http://www.pythonware.com/products/pil/

Or the friendly fork, Pillow?
https://pillow.readthedocs.io/en/4.3.x/

I think I used PIL before but not Pillow (maybe it didn’t exist back then), which someone has asked about 3d ago. There are several libraries out there. Just wondering which ones people find useful, friendly, efficient and well-documented.

1 Like

when I wrote my little image viewer in python a long time ago, I used pil (there was no pillow back then). I only needed basic stuff, but I found it very friendly.

the project has been dead for several years, but it has been recently resurrected and put on github by some good soul :slight_smile:
if anyone is interested:

(as I said it’s veery basic…)

@agriggio On Github:

It’s a very well done viewer that was well written

Well well, verily you have a fan :slight_smile:.

I know that there is Python 2 and 3: which one would you recommend using? Have most libraries and people jumped on to the 3 bandwagon?

for a new project without any legacy, there’s no reason to not use Python 3. (unless you have really specific needs like the Mercurial folks). Python 2 has been in maintenance-only mode for a long time…

1 Like

I think it really depends on what you want to do in terms of image processing. There is a lot of work being done on image recognition, with and without machine learning. Python is very strong in this respect.

My main experience of image wrangling in Python is with openCV for structure from motion analysis. Perhaps not the most user friendly place to start. I still do everything in Python2, but I know I should switch to 3. If you are in windows, just use Anaconda to get your Python installation up and running. Way easier than trying to do it all yourself. I use Pip on Linux.

Thanks for the feedback so far. I will start with Python 3, PIP and Pillow.

@Isaac I dabbled in OpenCV around the same time I experimented with Python (very long ago) and I agree that it was annoying to set up; esp. on win7. Anaconda looks convenient and unwieldy at the same time.

1 Like

My forner colleague built a document processing pipeline in Python using Anaconda on windows and he really liked the anaconda distribution.

I just installed Python 3 and pip on my win7 system. Looks like I have Python 2 and its corresponding pip as well. How do I know which Python I am using? When I do

>*.py

it is Python 2.

When I do

>python *.py
>pip

it is Python 3. I hope that this doesn’t confuse me too much :slight_smile:.

Python is nice as a quick and dirty way to test algorithms but I wouldn’t use it for regular processing. You will notice soon enough that, as pictures become larger, Python becomes less usable.

Indeed. Like you said, I am testing stuff.

You need to set your Python path variable correctly. On Linux, you could do this in the shebang of the script:

#!/usr/bin/python3

Or in your .bashrc profile.

export PYTHONPATH=/usr/bin/python3

These map the $ python command to a specific Python version. Otherwise, just specify the version on the CL when you run your script:

$ python2 myscript.py

Honestly, wrangling the paths is the biggest pain of having both Python2 and Python3 installed on the same system. One if my machines is hopelessly entangled because I f’ed up the paths at one point by using sudo pip3 to install some Python3 packages instead of just pip3 and haven’t been able to fix it yet This is one of the reasons why people prefer Anaconda over a system wide install. It keeps all your versions separated.

@Isaac I am not that far into Python yet :slight_smile:. I have already removed the other pip from the system path but kept python2 because an app or two require it. Anyway, I will try to remember to shebang the scripts.

PS Oops, it looks like I installed the 32bit version.

1 Like

Ok, so here is my toolkit:

  1. Numpy for array operations
  2. PIL for 8 bits image I/O
  3. tifffile or pylibtiff for 16 bits image I/O
  4. scipy.ndimage and scikit-image for processing/filters
  5. Image Magick and OpenCV wrappers for image manipulations
  6. Cython + prange/openMP loop to parallelize low-level vectorized loops

njoy !

1 Like