In some image analysis and machine vision applications—such as industrial defect inspection or biomedical imaging—segmentation based on thresholding or edge detection is not sufficient because the image quality is insufficient or the objects under inspection touch or overlap. In such applications, morphological segmentation is an effective method of image segmentation. Morphological segmentation partitions an image based on the topographic surface of the image. The image is separated into non-overlapping regions with each region containing a unique particle.

When to Use

Thresholding can segment objects from the background only if the objects are well separated from each other and have intensity values that differ significantly from the background. Binary morphology operators, such as close or open, often return inaccurate results when segmenting overlapping particles.

Use morphological segmentation to segment touching or overlapping objects from each other and from the background. Also, use morphological segmentation when the objects have intensity values similar to the background.
Note The morphological segmentation process described in the following section works best when the objects under inspection are convex.

Concepts

Morphological segmentation is a multiple-step process involving several Vision functions. The following list describes each morphological segmentation step and where to find more information about each step.

  1. Use a global or local threshold to create a binary image. Refer to global grayscale thresholding, global color thresholding, or local thresholding for more information about thresholding.
  2. If necessary, use binary morphology operations to improve the quality of the image by filling holes in particles or remove extraneous noise from the image.
  3. Use the Danielsson function to transform the binary image into a grayscale distance map in which each particle pixel is assigned a gray-level value equal to its shortest Euclidean distance from the particle border.
  4. Perform a watershed transform on the distance map to find the watershed separation lines.
  5. Superimpose the watershed lines on the original image using an image mask.

The following figure summarizes the morphological segmentation process and shows an example of each step.

Watershed Transform

In geography, a watershed is an area of land from which all rain that falls on the land flows into a specific body of water. In imaging, the watershed transform algorithm considers the objects under inspection to be the bodies of water. The following figure illustrates this concept.

  • Figure A shows an inspection image after it has been thresholded.
  • Figure B shows the distance map of objects in the image using the gradient palette.
  • Figure C shows the topographic surface of the distance map.

Each object from the inspection image forms a deep, conical lake called a catchment basin. The pixels to which the distance map function assigned the highest value represent the deepest parts of each catchment basin. The image background represents the land surrounding the catchment basins.

To understand how a watershed transform works, imagine that the catchment basins are dry. If rain were to fall evenly across the image, the basins would fill up at the same rate. Eventually, the water in the basins represented by the circle and square would merge, forming one lake. To prevent the two lakes from becoming one, the watershed transform algorithm builds a dam, or watershed line, where the waters would begin to mix.

Figure A shows the same distance map as Figure B with a line through the bottom two objects. Figure B shows the intensities of the pixels along the line in figure A. Notice the watershed line preventing the waters from the two catchment basins from mixing.

As the rainfall continues, the rising water in all three lakes would begin to flood the land. The watershed transform algorithm builds dams on the land to prevent the flood waters from each lake from merging. The following figure shows the watershed transform image after segmentation is complete. The water from each catchment basin is represented by a different pixel value. The black lines represent the watershed lines.

In-Depth Discussion

Vincent and Soille's Algorithm

The Vincent and Soille's algorithm fills catchment basins from the bottom up. Imagine that a hole is located in each local minimum. When the topographic surface is immersed in water, water starts filling all the catchment basins, minima of which are under the water level. If two catchment basins are about to merge as a result of further immersion, the algorithm builds a vertical dam up to the highest surface altitude. The dam represents the watershed line. The core algorithm of the Vision watershed transform function is based on Vincent and Soille's algorithm. The concept behind the Vision implementation of Vincent and Soille's algorithm is to sort the pixels in decreasing order of their grayscale values, followed by a flooding step consisting of a fast breadth-first scanning of all pixels in the order of their grayscale values.