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.
| 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:
| 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 |

Select the image that you want to perform a morphological operation on.
A grayscale image can be
converted to binary using the **ApplyThreshold** module. Objects can be
converted to binary using the **ConvertToImage** module.

Enter the name for the output image It will be of the same type as the
input image.

Choose one of the operations described in this module's help.

This setting controls the number of times that the same operation is applied
successively to the image.

*Once:*Perform the operation once on the image.*Forever:*Perform the operation on the image until successive iterations yield the same image.*Custom:*Perform the operation a custom number of times.

Enter the number of times to repeat the operation

Morphological open, close, erode and dialate are performed
with structuring elements which determine the diameter of the
circle enclosing the pixels to consider when applying the operation.
This setting controls the diameter of the structuring element.

The structuring element controls which neighboring pixels participate in the operation. For instance, for the erode operation, all pixels in the neighborhood of the pixel must be in the foreground for the pixel to be in the foreground in the output image. If a circular structuring element is used, then a pixel will be in the foreground only if all neighborhood pixels within a circle surrounding the pixel are in the foreground in the input image.

The structuring elements are:

*Disk*: A disk centered on the pixel. The scale setting determines the circle's diameter and all pixels that are at or closer than that diameter will be in the neighborhood.*Custom*: A structuring element which lets the user choose the exact neighborhood pixels to use.*Diamond*: A diamond centered on the pixel. The scale setting determines the distance between the top and bottom and left and right corners of the diamond.*Line*: A line centered on the pixel. The line has two settings. The angle setting gives the rotation of the line in the counter-clockwise direction in degrees, with a horizontal line having an angle of zero. The length of the line is determined by the scale setting - only pixels at or closer than 1/2 of the scale are included in the neighborhood. The line is drawn using the Bresenham algorithm.*Octagon*: An octagon centered on the pixel. The octagon is inscribed inside a square. The scale setting controls the length of the square's side. The scale is rounded to the nearest integer in the series, n * 6 + 1 so a perfect octagon can be drawn.*Pair*: The neighborhood of the pixel is composed of the pixel itself and the pixel at the x and y offsets given by the settings.*Periodic line*: The points along a line described by an offset, centered on the pixel. The periodic line has three settings. The neighborhood pixels are all within a circle whose diameter is the scale setting. Within the circle, pixels are chosen at N times the x and y offset from the center for positive and negative values of N.*Rectangle*: A rectangle centered on the pixel. The rectangle's height and width are given by two settings.*Square*: a square centered on the pixel. The scale setting determines the length of the square's side.

Select *Yes* to rescale the transformed values to lie between 0 and 1.
This is the option to use if the distance transformed image is to be used
for thresholding by an **Identify** module or the like, which assumes
a 0-1 scaling.

Select *No* to leave the values in absolute pixel units.
This useful in cases where the actual pixel distances are to be used
downstream as input for a measurement module.