State of Pymorph Address

Friends, Romans, countrymen, lend me your ears:

Actually, I was just looking for a quick 'n dirty Python morphology library to do a kind of string length image analysis and pymorph looked promising. Sadly, a major overhaul seems to be going on there right now, so while the actual code I ended up with is nice, short and robust, getting there was quite a pain.
Pymorph's old (<= 0.8) version has some very helpful demonstration pages, which have to be adapted for the new version (0.92 - and I found nothing but win32 packages for 0.8). Some hints are given on the developer's page, but quite a lot one has to figure out for oneself - mostly formatting issues.
  1. name space sanitisation - the mm prefix has been discarded as unpythonic. Most old functions work if you drop the prefix.
  2. Some things like image importing and display are already implemented in PIL and matplotlib, so they have been dropped altogether. This leaves the question what data type the pymorph functions will actually work with, and it turns out it's numpy arrays - boolean for binary images, uint 2-d arrays for greyscale.
  3. To replace pymorph's mmshow(), one could just use PIL's show() routine, which is a xv wrapper. To get it to work, you either have to install the venerable xv, or, as proposed here, hack a symlink to ImageMagick's display.
To illustrate, here is some basic example code (blob labelling a greyscale image, e.g. the one above):
import pymorph as p
import numpy as n
from PIL import Image
im=n.asarray(im) #convert to numpy array
bin=im>50 # binarise to boolean array
a=p.label(bin) # do blob labelling
Image.fromarray((a*255/n.amax(a)).astype(n.uint8)).show() #scale contrast and display
p.blob(a,'area',output='data') #blob sizes
Anyway, I'm glad the library is still around. Kudos to the developers.

PS: Official feedback (see comments): The 1.0 release including new tutorials is approaching.


luispedro said...


I am maintaining pymorph.

The recommended datatype for pymorph is numpy arrays.

The only reason why the code isn't tagged 1.0 is documentation and testing. I am working on it as, though, and it is actively maintained.

Also, expect a few tutorials and other documentation on python and image processing very soon...

avocadohead said...

Hi, thanks for the official feedback!
As it took me longer to figure out the input format than adapting the code I ended up with, I thought I'd drop a few hints in the blogosphere ... It's great you took over the maintenance - a library a comparative morphology noob is able to use within an hour is a godsend...
Are you going to adapt the old mmorph tutorials to the new namespace or are you doing your own examples?

luispedro said...

"""Are you going to adapt the old mmorph tutorials to the new namespace or are you doing your own examples?"""

both :)