Download: latest (1.8.0)

pymagery — python imagery


1.8.0 documentation / morph_close plugin

The morph_close plugin performs morphological close of a monochrome image (a dilation followed by an erosion). Closing has the general purpose of closing off notches of an image. It is closely related to the open operation.

The plugin prototype is:

def morph_close(mask, origin)

The mask must be another monochrome image and the origin is a zero-based two-tuple of the position that should be considered the origin of the mask. For square-masks of odd dimensions typically have the center pixel ((width-1)/2) as the origin. Of course, masks need not be square nor be fully filled in.

The following example closes the image with a 5x5 mask (center is the origin):

import pymagery mask = pymagery.image().NEW(5,5, pymagery.modes.MODE_MONO) + 1 i = pymagery.image('foo.ppm') i.morph_close(mask, (3,3))

The following is the result of dilation and closing of a 5x5 mask to an image.

Original Mask Dilated Image Closed Image
11111
11111
11111
11111
11111

In this case the dilation mask did not close off the notch in the top-right, thus the image has not changed because of the closing. Repeating the close operation with a 13x13 mask is big enough to close off the notch:

Original Dilated Image Closed Image

Change Log