Simple morphological operations in Python