This module performs a series of morphological operations on a binary image or grayscale image, resulting in an image of the same type. Many require some image processing knowledge to understand how best to use these morphological filters in order to achieve the desired result. Note that the algorithms minimize the interference of masked pixels; for instance, the dilate operation will only consider unmasked pixels in the neighborhood of a pixel when determining the maximum within that neighborhood.
The following operations are available:
Operation | Description | Input image type allowed |
Bothat | Bottom-hat filter: A bottom-hat filter enhances black spots in a white background. It subtracts the morphological Close of the image from the image. See below for a description of Close. | Binary, grayscale |
Branchpoints | Removes all pixels except those that are the branchpoints of a skeleton. This operation should be applied to an image after skeletonizing. It leaves only those pixels that are at the intersection of branches. 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | | → | ? | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ? | 0 | 0 | 0 | ? | | | Binary |
Bridge | Sets a pixel to 1 if it has two non-zero neighbors that are on opposite sides of this pixel: | Binary |
Clean | Removes isolated pixels: | Binary |
Close | Performs a dilation followed by an erosion. The effect is to fill holes and join nearby objects. | Binary, grayscale |
Convex hull | Finds the convex hull of a binary image. The convex hull is the smallest convex polygon that fits around all foreground pixels of the image: it is the shape that a rubber band would take if stretched around the foreground pixels. The convex hull can be used to regularize the boundary of a large, single object in an image, for instance, the edge of a well. | Binary |
Diag | Fills in pixels whose neighbors are diagnonally connected to 4-connect pixels that are 8-connected: | Binary |
Dilate | For binary, replaces any 0 pixel by 1 if any of its neighbors is 1. For grayscale, each pixel is replaced by the maximum of its neighbors and itself. | Binary, grayscale |
Distance | Computes the distance transform of a binary image. The distance of each foreground pixel is computed to the nearest background pixel. The resulting image is then scaled so that the largest distance is 1. | Binary |
Erode | For binary, replaces any 1 pixel by 0 if any of its neighbors is 0. For grayscale, each pixel is replaced by the minimum of its neighbors and itself. | Binary, grayscale |
Endpoints | Removes all pixels except the ones that are at the end of a skeleton: 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | | → | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ? | 0 | 0 | ? | | | Binary |
Fill | Sets a pixel to 1 if all of its neighbors are 1: | Binary |
Fill small holes | Sets background pixels surrounded by foreground pixels to 1. This operation fills in small holes in a binary image. You can set the maximum area of a hole in order to restrict the operation to holes of a given size or smaller. | Binary |
Hbreak | Removes pixels that form vertical bridges between horizontal lines: | Binary |
Invert | For a binary image, transforms background to foreground and vice-versa. For a grayscale image, invert its intensity. | Binary, Grayscale |
Majority | Each pixel takes on the value of the majority that surround it (keep pixel value to break ties): | Binary |
Life | Applies the interaction rules from the Game of Life, an example of a cellular automaton. | Binary |
Open | Performs an erosion followed by a dilation. The effect is to break bridges between objects and remove single pixels. | Binary, grayscale |
Remove | Removes pixels that are otherwise surrounded by others (4 connected). The effect is to leave the perimeter of a solid object: | Binary |
Shrink | Performs a thinning operation that erodes unless that operation would change the image's Euler number. This means that blobs are reduced to single points and blobs with holes are reduced to rings if shrunken indefinitely. | Binary |
Skel | Performs a skeletonizing operation (medial axis transform). Preserves the points at the edges of objects but erodes everything else to lines that connect those edges. See here for a description. | Binary |
SkelPE | Performs a skeletonizing operation using the metric, PE * D to control the erosion order. PE is the Poisson Equation (see Gorelick, "Shape representation and classification using the Poisson Equation", IEEE Transactions on Pattern Analysis and Machine Intelligence V28, # 12, 2006) evaluated within the foreground with the boundary condition that the background is zero. D is the distance transform (distance of a pixel to the nearest edge). The resulting skeleton has fewer spurs but some bit of erosion at the endpoints in the binary image. | Binary |
Spur | Removes spur pixels, i.e., pixels that have exactly one 8-connected neighbor. This operation essentially removes the endpoints of lines. | Binary |
Thicken | Dilates the exteriors of objects where that dilation does not 8-connect the object with another. The image is labeled and the labeled objects are filled. Unlabeled points adjacent to uniquely labeled points change from background to foreground. | Binary |
Thin | Thin lines preserving the Euler number using the thinning algorithm # 1 described in Guo, "Parallel Thinning with Two Subiteration Algorithms", Communications of the ACM, Vol 32 #3, page 359. The result generally preserves the lines in an image while eroding their thickness. | Binary |
Tophat | Subtracts the morphological opening of the image from the image. This enhances white spots in a black background. | Binary, grayscale |
Vbreak | Removes pixels that form horizontal bridges between vertical lines: | Binary |