Binary Image Morphology

Morphological processes work much like spatial convolution in that pixel values are based on values of the neighboring pixels. Instead of constructing a dot product of a mask array and a pixel array, morphological processes use set theory operations such as intersection (AND), union (OR), and complement (NOT) to combine pixels logically into a resulting pixel value.

The mask array in spatial convolution becomes the structuring element in morphology.

Hit or Miss Transformations

For the 3 x 3 structuring element case, neighboring pixels are converted to a one-dimensional array using the following pattern.

The objective is to determine a value for the central pixel, shown below.

A simplified example for the morphological process is

This general implementation is called the hit or miss transform. When the mask values match their respective pixel values, we have a hit. Otherwise, it is a miss.

Dilation and Erosion

Dilation

Dilation returns 0 if all nine pixels are 0 and 1 otherwise.

B is the structuring element, often a 3 x 3 array of 1's (ones(3)).

originaldilated oncedilated twice

Erosion

Erosion returns 1 if all nine pixels are 1 and 0 otherwise.

B is the structuring element, often a 3 x 3 array of 1's (ones(3)).

originaleroded onceeroded twice

Opening and Closing

Opening

Opening is the erosion of A by structuring element B followed by dilation by the same structuring element.

Opening generally smooths the contour of an image, breaks narrow passages, and eliminates narrow protrusions.

originalepened

Closing

Closing is the dilation of A by structuring element B followed by erosion by the same structuring element.

Closing tends to smooth the contour of an image but, as opposed to opening, it fuses narrow breaks and long thin gulfs, eliminates small holes, and fills gaps in the contour.

originalclosed

tophat and bothat

bothatSubtract the input image from its closing
tophatSubtract the opening from the input image

originalbot hattop hat

Skeleton

Remove pixels from the boundaries of objects without changing their 8-connectivity

originaln = 1n = 2
n = 3n = 4n = Inf

Shrink

Shrink objects without holes to single pixels; shrink objects with holes to connected rings

originaln = 1n = 2
n = 3n = 4n = Inf

Thin

Shrink objects without holes to lines; shrink objects with holes to connected rings.

originaln = 1n = 2
n = 3n = 4n = Inf

Remove

Set a pixel to 0 if its 4-connected neighbors are all 1's, thus leaving only boundary pixels.

originalremoved

Thicken

Add pixels to the boundaries of objects without changing their 8-connectivity

originalthickened

Pruning


original images
clean removes isolated pixels (1's surrounded by 0's)
majority Set a pixel to 1 if five or more pixels in its 3-by-3 neighborhood are 1's
spur Remove spur pixels

Binary image morphological operations in Matlab.

BWMORPH

   BW2 = BWMORPH(BW1,OPERATION) applies a specific
   morphological operation to the binary image BW1.  

   The input image BW1 can be of class double or uint8.  The
   output image BW2 is of class uint8.

   BW2 = BWMORPH(BW1,OPERATION,N) applies the operation N
   times.  N can be Inf, in which case the operation is repeated
   until the image no longer changes.

   OPERATION is a string that can have one of these values:
      'bothat'   Subtract the input image from its closing
      'bridge'   Bridge previously unconnected pixels
      'clean'    Remove isolated pixels (1's surrounded by 0's)
      'close'    Perform binary closure (dilation followed by
                   erosion)  
      'diag'     Diagonal fill to eliminate 8-connectivity of
                   background
      'dilate'   Perform dilation using the structuring element
                   ones(3) 
      'erode'    Perform erosion using the structuring element
                   ones(3) 
      'fill'     Fill isolated interior pixels (0's surrounded by
                   1's)
      'hbreak'   Remove H-connected pixels
      'majority' Set a pixel to 1 if five or more pixels in its
                   3-by-3 neighborhood are 1's
      'open'     Perform binary opening (erosion followed by
                   dilation) 
      'remove'   Set a pixel to 0 if its 4-connected neighbors
                   are all 1's, thus leaving only boundary
                   pixels
      'shrink'   Shrink objects without holes to single pixels;
                   shrink objects with holes to connected rings
      'skel'     Remove pixels from the boundaries of objects
                   without changing their 8-connectivity
      'spur'     Remove spur pixels
      'thicken'  Add pixels to the boundaries of objects
                   without changing their 8-connectivity
      'thin'     Shrink objects without holes to lines; shrink
                   objects with holes to connected rings
      'tophat'   Subtract the opening from the input image


Maintained by John Loomis, last updated 23 July 1997