Next: 2.11 Mosaicing Up: 2. VIPS packages Previous: 2.9 Histograms and LUTs Contents

# 2.10 Morphology

See figure 2.12.

The morphological functions are used on one-band `IM_BANDFMT_UCHAR` binary images (images containing only zero and not-zero). They search images for particular patterns of pixels (specified with the mask argument), either adding or removing pixels when they find a match. They are useful for cleaning up images -- for example, you might threshold an image, and then use one of the morphological functions to remove all single isolated pixels from the result.

If you combine the morphological operators with the mask rotators (`im_rotate_imask45()`, for example) and apply them repeatedly, you can achieve very complicated effects: you can thin, prune, fill, open edges, close gaps, and many others. For example, see `Fundamentals of Digital Image Processing' by A. Jain, pp 384-388, Prentice-Hall, 1989 for more ideas.

Beware that VIPS reverses the usual image processing convention, by assuming white objects on a black background.

The mask you give to the morphological functions should contain only the values 0 (for background), 128 (for don't care) and 255 (for object). The mask must have odd length sides -- the origin of the mask is taken to be the centre value. For example, the mask:

    3 3
    128 255 128
    255 0   255
    128 255 128

applied to an image with `im_erode()`, will find all black pixels 4-way connected with white pixels. Essentially, `im_dilate()` sets pixels in the output if any part of the mask matches, whereas `im_erode()` sets pixels only if all of the mask matches.

The `_raw()` version of the functions do not add a black border to the output. `im_cntlines()` and `im_profile` are occasionally useful for analysing results.

See the boolean operations `im_and()`, `im_or()` and `im_eor()` for analogues of the usual set difference and set union operations.

Figure 2.12: Morphological functions

Next: 2.11 Mosaicing Up: 2. VIPS packages Previous: 2.9 Histograms and LUTs Contents