Morphological
TD COMPs / TOPs / 2023 – Present
Morphological transformations form the backbone of many image processing tasks, offering a powerful set of tools to manipulate the structure of images. These operations focus on the shape and structure within an image, enabling you to enhance or extract features, remove noise, and perform shape analysis.
By applying morphological transformations they allow you to modify image regions based on their spatial form. These tools are essential for refining the structure of objects, isolating specific features, and preparing images for more advanced analysis like segmentation, object detection, and pattern recognition.
Index:
Dilate/Erode, Dynamic Dilate/Erode, Feature Detector, Geodesic Dilate/Erode, Gradient, Hit‐or‐Miss, Opening/Closing, Perimeter, Pruning, Smoothing, Thinning/Thickening, Top/Bottom Hat
Dilate/Erode
Fundamental Morphological Operation
Dilation and Erosion are the two fundamental operations in mathematical morphology. These operations are primarily used on binary images but can also be applied to grayscale or even color images, providing a versatile solution for a range of image processing tasks.
Dilation ( ) expands the boundaries of regions containing foreground pixels (typically white pixels), effectively enlarging objects in the image. This operation is useful for closing small holes and connecting disjointed elements within the image, making it ideal for tasks like filling gaps or enhancing specific features.
Erosion ( ), on the other hand, contracts the boundaries of regions containing foreground pixels. This operation is used to shrink objects, remove small noise, and separate connected elements, making it particularly useful for refining object boundaries and eliminating minor imperfections.
In conjunction, the Dilate/Erode component allows for precise control over the structure and features within an image, making it indispensable for tasks such as feature extraction, noise reduction, and image pre-processing.
Resources:
Download the .tox files
HIPR2 Morphology documentation
Dilation on Wikipedia
Erosion on Wikipedia
Parameters
Mode:
Determines the operation to be performed on the input image. Dilation, which expands the boundaries of the foreground objects, or Erosion, which shrinks them.
Depth:
Specifies the number of iterations that the morphological operation will be applied to the input image.
Dimensions:
Defines the width and height of the structuring element to be used in the morphological operation, directly affecting the scope of the operation on the image.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Roundness:
Adjusts the shape of the default structuring element. A value of 0 creates a square element, while a value of 1 produces a circular element.
In‐ / Outputs
Input 0 – TOP image to be processed.
Input 1 – TOP binary image to be used as the structuring element.
Output 0 – TOP processed image.
Dynamic Dilate/Erode
Localized Morphological Control
This component expands on the functionality of traditional dilation and erosion by combining both morphological operations into a single component while providing fine-grained control over how much to dilate or erode the input image at each pixel.
The first input, as is the case with the other morphological operators, is the image to be transformed, whether binary, grayscale, or color. The second input, however, sets this component apart. Instead of applying a uniform dilation or erosion, a 16‐bit or 32‐bit float monochrome morphology mask dictates the operation.
Notice: The provided morphology mask will be automatically normalized between −1 and +1 to ensure it does not exceed the maximum morphological radius defined by the user. The normalized value of each pixel in the mask determines the intensity of the operation:
- Positive values: Indicate dilation, with the magnitude scaling the effect relative to the maximum radius.
- Negative values: Indicate erosion, similarly, with the magnitude scaling the effect relative to the maximum radius.
- Zero values: Leave the pixel unchanged.
This dynamic approach enables localized morphological transformations, blending dilation and erosion across an image seamlessly. The Dynamic Dilate/Erode component is an essential tool for applications requiring region-specific enhancements, noise reduction, or feature refinement, offering unparalleled precision and adaptability in the morphological suite.
Resources:
Download the .tox files
HIPR2 Morphology documentation
Dilation on Wikipedia
Erosion on Wikipedia
Parameters
Depth:
Specifies the number of iterations that the morphological operation will be applied to the input image.
Dimensions:
Defines the width and height of the structuring element to be used in the morphological operation, directly affecting the scope of the operation on the image.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Roundness:
Adjusts the shape of the default structuring element. A value of 0 creates a square element, while a value of 1 produces a circular element.
In‐ / Outputs
Input 0 – TOP image to be processed.
Input 1 – TOP 16‐bit or 32‐bit float monochrome image used to define the amount of dilation and erosion.
Output 0 – TOP processed image.
Feature Detector
Edge Differentiation & Texture Analysis
This Morphological Feature Detector component leverages grayscale morphological operations to distinguish and analyze different types of edges in an image, separating smooth "ramp" edges from "texture" edges caused by ripples or noise. This capability makes it an advanced tool for detecting and classifying features with precision.
This component supports three modes of edge detection:
-
Dynamic Edges:
This operation produces results similar to a linear Laplacian filter, highlighting prominent transitions in intensity.
-
Texture Edges:
Emphasizes high-frequency details and noise by analyzing the transitions that remain after morphological smoothing (opening) and sharpening (closing).
-
Ramp Edges:
Emphasizes smooth gradients by analyzing the morphological transitions between dilation, erosion, opening, and closing.
The Morphological Feature Detector is ideal for identifying and separating textures from smooth gradients, enhancing specific edge types for image analysis and preprocessing, or noise reduction and feature enhancement in complex images.
Resources:
Parameters
Mode:
Selects the type of features to detect in the input image
Output Format:
Defines the pixel format of the output image.
Depth:
Specifies the number of iterations that the morphological operation will be applied to the input image.
Dimensions:
Defines the width and height of the structuring element to be used in the morphological operation, directly affecting the scope of the operation on the image.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Roundness:
Adjusts the shape of the default structuring element. A value of 0 creates a square element, while a value of 1 produces a circular element.
In‐ / Outputs
Input 0 – TOP image to be processed.
Input 1 – TOP binary image to be used as the structuring element.
Output 0 – TOP processed image.
Geodesic Dilate/Erode
Iterative Constrained Transformations
This component performs iterative morphological transformations constrained by a mask image (input 1), enabling precise control over the extent and boundaries of the dilation or erosion. This operation is foundational in more complex morphological operations like reconstruction and feature isolation.
In this context, “geodesic” refers to transformations that are guided by a mask image (input 1), which restricts where the dilation or erosion can occur. The mask serves as a constraint, ensuring the operation is confined to specific regions of the image. This makes geodesic transformations particularly useful for preserving structure while refining details.
Notice: A Feedback TOP is used to propagate the iterative dilation/erosion throughout the provided mask. As a result, you will need to let the calculation run over multiple frames for the dilation/erosion process to fully complete.
Resources:
Parameters
Mode:
Determines the operation to be performed on the input image. Dilation, which expands the boundaries of the foreground objects, or Erosion, which shrinks them.
Depth:
Specifies the number of iterations that the morphological operation will be applied to the input image.
Dimensions:
Defines the width and height of the structuring element to be used in the morphological operation. Larger values increase the scope of the operation but may cause the iterative process to jump across small borders in the mask image. Keeping the structuring element small ensures better control.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Roundness:
Adjusts the shape of the default structuring element. A value of 0 creates a square element, while a value of 1 produces a circular element.
Reset:
Resets the feedback loop, restarting the transformation from the initial state.
In‐ / Outputs
Input 0 – TOP image to be processed.
Input 1 – TOP mask image that constrains where the dilation or erosion is allowed to occur.
Input 2 – TOP binary image to be used as the structuring element.
Output 0 – TOP processed image.
Gradient
Boundary Enhancement & Edge Detection
This morphological transformation extends the foundational concepts of dilation and erosion to provide a nuanced analysis of object boundaries within an image. By measuring the difference between dilation and erosion it highlights the edges of objects and enhances the visibility of contours. By focusing on the transitions between foreground and background regions, the Morphological Gradient is particularly useful for tasks such as edge detection, texture analysis, and feature extraction.
This component offers three distinct methods for calculating gradients, each tailored to specific aspects of image structure:
-
Gradient:
The standard morphological gradient is calculated as the difference between the dilated and eroded versions of the input image. This method accentuates the boundaries of objects, making it ideal for general edge detection.
-
Internal Gradient:
Computed as the difference between the original image and its eroded version, this method emphasizes the inner edges of foreground objects. It’s particularly useful when the goal is to highlight the boundaries within larger structures.
-
External Gradient:
Calculated as the difference between the dilated image and the original, this method focuses on the outer edges of foreground objects. It’s effective for enhancing the external contours and separating closely spaced elements.
By selecting the appropriate gradient type, the Morphological Gradient component allows for precise control over how boundaries are interpreted and emphasized.
Resources:
Download the .tox files
HIPR2 Morphology documentation
Morphological Gradient on Wikipedia
Parameters
Method:
Selects the type of gradient to compute.
Depth:
Specifies the number of iterations that the morphological operation will be applied to the input image.
Dimensions:
Defines the width and height of the structuring element to be used in the morphological operation, directly affecting the scope of the operation on the image.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Roundness:
Adjusts the shape of the default structuring element. A value of 0 creates a square element, while a value of 1 produces a circular element.
In‐ / Outputs
Input 0 – TOP image to be processed.
Input 1 – TOP binary image to be used as the structuring element.
Output 0 – TOP processed image.
Hit‐or‐Miss
Pattern Recognition
The Hit‐or‐Miss transformation offers a nuanced method to detect specific patterns of pixels within an image. Unlike simpler morphological operations, the Hit‐or‐Miss utilizes a more complex structuring element, one that considers both foreground and background pixels.
The operation works by parsing the input image with a chosen set of structuring elements. When structuring elements are grouped like this, they are referred to as a Composite Structuring Element ( ). For example, when the component’s Mode parameter is set to Concave Corners, as shown in the example on the right, the input image will be parsed with the following structuring elements:
Notice, each consecutive element in the composite structuring element is the previous one rotated by 90°. This ensures that the operation can detect the desired feature regardless of its orientation in the image.
When an image is processed with a Hit‐or‐Miss transformation ( ). Active pixels are returned only where any structuring elements in the composite is fulfilled exactly. The result is typically a mostly black image with points indicating where the specified criteria have been met.
This component is ideal for detecting precise features like corners, intersections, or other specific patterns in an image, making it a powerful tool for tasks such as pattern recognition and feature analysis.
Resources:
Download the .tox files
HIPR2 Hit‐and‐Miss documentation
Hit‐or‐Miss on Wikipedia
Parameters
Mode:
Specifies the type of features and different structural patterns to identify and isolate within the input image.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Invert structuring element:
When on, this will invert the sign of each cell of the structuring element.
In‐ / Outputs
Input 0 – TOP image to be processed.
Output 0 – TOP processed image.
Opening/Closing
Noise Reduction & Structural Enhancement
Opening and Closing are the next step in complexity in mathematical morphology, building off of Dilation and Erosion to achieve more refined and targeted image processing outcomes. These operations are designed to enhance the structure of objects within an image by combining the effects of Dilation and Erosion in sequence. Whether working with binary, grayscale, or color images, Opening and Closing provide a powerful means of noise reduction, object isolation, and structural enhancement, making them indispensable for advanced image processing tasks.
Opening ( ) is the process of first eroding and then dilating an image. This sequence is particularly effective at removing small objects or noise while preserving the overall shape and size of larger objects. Opening is ideal for tasks such as eliminating minor imperfections, separating closely spaced objects, and preparing images for further analysis by removing extraneous details.
Closing ( ) reverses this process by first dilating and then eroding an image. This operation is especially useful for filling small holes and gaps within objects, smoothing contours, and connecting adjacent elements that should be unified. Closing is commonly used in scenarios where it's necessary to enhance the continuity of object structures while still retaining their general form.
Resources:
Download the .tox files
HIPR2 Morphology documentation
Opening on Wikipedia
Closing on Wikipedia
Parameters
Mode:
Determines the operation to be performed on the input image. Opening, which smooths the contour of the foreground objects, or Closing, which fills small holes and gaps in foreground objects.
Depth:
Specifies the number of iterations that the morphological operation will be applied to the input image.
Dimensions:
Defines the width and height of the structuring element to be used in the morphological operation, directly affecting the scope of the operation on the image.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Roundness:
Adjusts the shape of the default structuring element. A value of 0 creates a square element, while a value of 1 produces a circular element.
Blur Pre‐Shrink:
Reduces the resolution of the default structuring element before applying the blur, allowing for faster processing and smoother results on the edges.
Blur Filter Size:
Controls the amount of blur applied to the default structuring element in pixels. Larger values increase the blur, corroding the edges of the shape.
Density:
Adjusts the density of the default structuring element. At a value of 1, the element remains fully dense. Lowering this value reduces the density, creating a more sparse structure.
In‐ / Outputs
Input 0 – TOP image to be processed.
Input 1 – TOP binary image to be used as the structuring element.
Output 0 – TOP processed image.
Perimeter
Single‐Pixel Boundary Extraction
This component is a simplified version of the Gradient component, specifically designed to extract a continuous single‐pixel‐thick boundary of objects within an image. While it can process grayscale or even color images, it works best with binary inputs, where it reliably defines perimeters. On non-binary images, results may vary, as the component is less able to clearly delineate object boundaries.
The Method parameter determines how the perimeter is calculated:
- Outline: Extracts the outer boundary of objects by subtracting the dilated image from the input.
- Inline: Extracts the inner boundary of objects by subtracting the input from the eroded image.
This component is ideal for tasks that require a clean, precise boundary of objects, such as contour detection, shape analysis, and segmentation refinement. For more advanced or nuanced edge detection, the Gradient component provides additional flexibility and detail.
Resources:
Download the .tox files
HIPR2 Morphology documentation
Morphological Perimeter on Wolfram
Parameters
Method:
Determines the type of perimeter to generate.
Structuring Element:
Specifies the structuring element used to define the perimeter. The choice of element influences the detail and characteristics of the generated perimeter.
Depth:
Specifies the number of iterations that the morphological operation will be applied to the input image.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
In‐ / Outputs
Input 0 – TOP image to be processed.
Output 0 – TOP processed image.
Pruning
Iterative Skeleton Simplification
This morphological operation finds the end points of thinned images (skeletons) and iteratively prunes their tips, refining the overall structure while preserving key features. The Pruning component is used to clean up skeletonized image, remove unwanted branches, and simplify complex shapes for more accurate analysis and processing.
The skeleton branch end points are detected using the Hit‐or‐Miss operation with two composite structuring elements, specifically designed to identify horizontal and diagonal skeletal terminals. Once detected, these endpoints are dilated using a standard dilation transformation, where the Dimensions and Roundness parameters define the structuring element”s size and shape. The dilated endpoints are then subtracted from the input skeleton to remove them:
This process constitutes a single iteration of the pruning operation. To prune longer branches, the component must run iteratively over multiple frames. For example, to prune 30 pixels from the ends of branches, set the Dimensions parameter to 3×3 and let the component run for 15 frames. Each iteration removes both the endpoint and its immediate neighboring pixel, progressively shortening the branch.
Resources:
Download the .tox files
HIPR2 Morphology documentation
Pruning on Wolfram
Pruning on Wikipedia
Parameters
Depth:
Specifies the number of iterations that the morphological operation will be applied to the input image.
Dimensions:
Defines the width and height of the structuring element to be used in the morphological operation, directly affecting the scope of the operation on the image.
Roundness:
Adjusts the shape of the default structuring element. A value of 0 creates a square element, while a value of 1 produces a circular element.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Reset:
Triggers a reset, reverting the image to its original state and allowing the operation to start over from the input image.
In‐ / Outputs
Input 0 – TOP image to be processed.
Output 0 – TOP processed image.
Smoothing
Morphological Surface Refinement
From dilation and erosion to opening and closing, this smoothing operation’s standard method serves as the natural next step in this progression. Defined as an opening followed or preceded by a closing or , this morphological transformation reduces noise and smooths both the textures and overall shapes of the input image.
In addition to the standard method, this component includes two other transformations with smoothing properties:
-
Image Smoothing:
Defined as the average of the eroded and dilated input image. This transformation is effective for reducing sharp transitions while maintaining the general intensity gradient.
-
Texture Smoothing:
Defined as the average of the opened and closed images. This transformation is useful for blending textures and reducing high-frequency details without significant loss of structural information.
These methods provide flexible and robust options for refining image content, whether you're focusing on reducing noise, softening textures, or preserving structural integrity. The Morphological Smoothing component is a versatile tool for preprocessing images, enhancing visual clarity, and preparing data for advanced analysis or visualization.
Resources:
Download the .tox files
HIPR2 Morphology documentation
Grayscale Morphological Analysis
Parameters
Mode:
Specify the type of smoothing to be performed on the input image.
Method:
Available when the Mode parameter is set to Standard.
Specifies the sequence of operations to be applied in order to calculate the morphological smoothing of the input image.
Depth:
Specifies the number of iterations that the morphological operation will be applied to the input image.
Dimensions:
Defines the width and height of the structuring element to be used in the morphological operation, directly affecting the scope of the operation on the image.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Roundness:
Adjusts the shape of the default structuring element. A value of 0 creates a square element, while a value of 1 produces a circular element.
In‐ / Outputs
Input 0 – TOP image to be processed.
Input 1 – TOP binary image to be used as the structuring element.
Output 0 – TOP processed image.
Thinning/Thickening
Iterative Morphological Skeletonization
Thinning and thickening are dual morphological operations designed to iteratively refine or expand binary images. When allowed to iterate to completion, these operations yield either the skeletal (thinning) or boundary (thickening) representation of the input image. Both operations are essential tools for structural analysis, shape refinement, and feature enhancement in binary image processing.
Both thinning and thickening rely on composite structuring elements to identify and process boundary pixels. These composite structuring elements are applied iteratively to either erode (thinning) or dilate (thickening) the edges of the input image. The process is executed within a feedback loop, enabling progressive transformations over multiple frames.
Thinning:
The composite structuring elements identify boundary pixels for removal without disconnecting the object’s structure. Iteratively applied, this operation reduces the object to its skeletal form, making it ideal for extracting the core topology of shapes.
Thinning uses the following structuring elements, along with their 90° rotational variants, to construct its composite structuring elements:
Thickening:
Similarly, composite structuring elements identify boundary pixels for expansion, progressively adding layers to the object’s edges. Thickening emphasizes and enhances boundaries, connecting disjointed elements and approximating convex hulls.
Thickening: uses the following structuring elements, along with their 90° rotational variants, to construct its composite structuring elements:
Remember, this is an iterative morphological transformation which means it must be run for multiple frames to properly process the input image.
Resources:
Download the .tox files
HIPR2 Morphology documentation
HIPR2 Thinning documentation
HIPR2 Thickening documentation
Parameters
Mode:
Selects the operation method to use. Thinning reduces the thickness of foreground objects to skeletal lines, or Thickening, which increases foreground objects thicknesses.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Reset:
Triggers a reset, reverting the image to its original state and allowing the operation to start over from the input image.
In‐ / Outputs
Input 0 – TOP image to be processed.
Output 0 – TOP processed image.
Top/Bottom‐Hat
Contrast Enhancement
By leveraging opening and closing transformations, this component is particularly useful for detecting bright or dark regions relative to their surroundings.
The Top‐Hat and Bottom‐Hat transformations are often referred to as White‐Hat and Black‐Hat transformations, respectively, in some literature. These terms come from the idea of isolating light (white) or dark (black) features in an image. However, the terms “Top‐Hat” and “Bottom‐Hat” are more widely accepted and recognized in image processing.
The Top‐Hat transformation highlights small, bright features in an image. Essentially isolating bright objects smaller than the structuring element, such as small blobs or peaks in intensity. This is achieved by subtracting the morphologically opened image from the original:
The Bottom‐Hat transformation, on the other hand, enhances dark features in an image. Effectively finding intensity troughs or isolating darker regions smaller than the structuring element. This is achieved by subtracting the original image from its morphologically closed version from the original:
These transformations make the Top/Bottom‐Hat component ideal for identifying small objects or elements based on their brightness or darkness relative to their surroundings, correcting nonuniform illumination in grayscale images for better segmentation or thresholding, enhancing contrast and visibility of subtle features, such as small bright spots or dark pits.
Resources:
Download the .tox files
Top‐Hat on Math Works,
Bottom‐Hat on Math Works,
Top‐Hat on Wikipedia
Parameters
Mode:
Determines the operation to be performed. Top-Hat highlights small elements in the foreground, or Bottom-Hat that emphasizes dark regions.
Depth:
Specifies the number of iterations that the morphological operation will be applied to the input image.
Dimensions:
Defines the width and height of the structuring element to be used in the morphological operation, directly affecting the scope of the operation on the image.
Edge Handling:
Determines how the edges of the image are treated during the morphological transformation. Extends the image to avoid edge artifacts.
Roundness:
Adjusts the shape of the default structuring element. A value of 0 creates a square element, while a value of 1 produces a circular element.
In‐ / Outputs
Input 0 – TOP image to be processed.
Input 1 – TOP binary image to be used as the structuring element.
Output 0 – TOP processed image.