New in version 0.8: open() & close() were added in version 0.8
Morphological operators were the first operations in mahotas (back then, it was even, briefly, just a single C++ module called morph). Since then, mahotas has grown a lot. This module, too, has grown and acquired more morphological operators as well as being optimised for speed.
Let us first select an interesting image
Dilation is, intuitively, making positive areas “fatter”:
Erosion, by contrast, thins them out:
Mahotas supports greyscale erosion and dilation (depending on the dtype of the arguments) and you can specify any structuring element you wish (including non-flat ones). By default, a 1-cross is used:
# if no structure-element is passed, use a cross: se = np.array([ [0, 1, 0], [1, 1, 1], [0, 1, 0]])
However, you can use whatever structuring element you want:
se = np.array([ [1, 1, 0], [1, 1, 1], [0, 1, 1]]) dilated = mahotas.morph.dilate(eye, se) eroded = mahotas.morph.erode(eye, se)
Closing and opening are based on erosion and dilation. Again, they work in greyscale and can use an arbitrary structure element.
Here is closing:
And here is opening:
Both close and open take an optional structuring element as a second argument: