Morphological Transformation¶
v2¶
Class: MorphologicalTransformationBlockV2 (there are multiple versions of this block)
Warning: This block has multiple versions. Please refer to the specific version for details. You can learn more about how versions work here: Versioning
Apply morphological transformations to color images using configurable operations to modify object shapes, remove noise, fill holes, detect edges, and extract features. Color images are processed with transformations applied to all channels, and the output is returned as color for compatibility with downstream processing blocks.
How This Block Works¶
This block applies morphological transformations directly to color images (BGR or BGRA). The block:
- Receives an input image to transform (works with color or grayscale images)
- Ensures image is in color format (if grayscale, converts to BGR for consistent color output)
- Creates a square structuring element (kernel) of specified kernel_size
- Applies the selected morphological operation to all channels simultaneously
- Preserves the color format throughout the transformation (including alpha channel for BGRA images)
- Returns the morphologically transformed color image
Supported operations:
- Erosion: Shrinks objects by removing boundary pixels (separates objects, removes noise)
- Dilation: Expands objects by adding boundary pixels (connects objects, fills holes)
- Opening: Erosion followed by dilation (removes noise, separates objects)
- Closing: Dilation followed by erosion (fills holes, connects fragments)
- Opening then Closing: Opens then closes (specialized preprocessing for edge detection and refinement)
- Gradient: Dilation minus erosion (highlights object boundaries/edges)
- Top Hat: Input minus opening (detects small bright details)
- Black Hat: Closing minus input (detects small dark details)
All operations preserve the color format, making output compatible with downstream color-based blocks like Mask Edge Snap.
Common Use Cases¶
- Color Image Preprocessing: Process color images while preserving color information for downstream blocks
- Edge Detection and Refinement: Use opening+closing for specialized preprocessing before edge snapping
- Noise Removal: Remove noise from color images while maintaining color channels
- Feature Extraction: Extract morphological features from color images
- Image Conditioning: Prepare color images for color-based downstream processing
Connecting to Other Blocks¶
- Before Mask Edge Snap: Output color images for edge snapping and mask refinement
- Before visualization blocks: Display morphologically processed color images
- In color image pipelines: Process color images while maintaining color information
Type identifier¶
Use the following identifier in step "type" field: roboflow_core/morphological_transformation@v2to add the block as
as step in your workflow.
Properties¶
| Name | Type | Description | Refs |
|---|---|---|---|
name |
str |
Enter a unique identifier for this step.. | ❌ |
kernel_size |
int |
Size of the square structuring element (kernel) used for morphological operations. Must be a positive integer. Typical values range from 3-15. Adjust based on object sizes and desired transformation scale.. | ✅ |
operation |
str |
Type of morphological operation to apply. 'Opening then Closing' is specifically designed for preprocessing before edge detection and mask refinement (e.g., with Mask Edge Snap block). All other operations follow standard morphological definitions.. | ✅ |
The Refs column marks possibility to parametrise the property with dynamic values available
in workflow runtime. See Bindings for more info.
Available Connections¶
Compatible Blocks
Check what blocks you can connect to Morphological Transformation in version v2.
- inputs:
Morphological Transformation,Roboflow Asset Library Attributes,Image Preprocessing,Florence-2 Model,Email Notification,VLM As Classifier,Halo Visualization,Morphological Transformation,EasyOCR,Pixel Color Count,Object Detection Model,Text Display,Template Matching,Image Threshold,Twilio SMS Notification,Local File Sink,Icon Visualization,Triangle Visualization,Qwen 3.5 API,Model Monitoring Inference Aggregator,Pixelate Visualization,Keypoint Detection Model,Microsoft SQL Server Sink,Qwen-VL,OpenAI,CogVLM,Crop Visualization,Dot Visualization,Google Vision OCR,OpenRouter,Florence-2 Model,Roboflow Dataset Upload,Distance Measurement,Qwen3.5-VL,Roboflow Vision Events,Polygon Zone Visualization,Polygon Visualization,OpenAI,SIFT Comparison,Background Color Visualization,Absolute Static Crop,S3 Sink,MoonshotAI Kimi,Twilio SMS/MMS Notification,QR Code Generator,SIFT Comparison,Contrast Enhancement,Google Gemini,Grid Visualization,Corner Visualization,Reference Path Visualization,Image Slicer,Single-Label Classification Model,Stitch OCR Detections,Line Counter,Halo Visualization,Dynamic Crop,Webhook Sink,OCR Model,Color Visualization,Stability AI Outpainting,Detection Event Log,Roboflow Dataset Upload,Roboflow Custom Metadata,LMM For Classification,OpenAI-Compatible LLM,Relative Static Crop,Image Blur,Line Counter Visualization,Stability AI Inpainting,Blur Visualization,Anthropic Claude,Clip Comparison,Multi-Label Classification Model,Current Time,OpenAI,Perspective Correction,Keypoint Visualization,Llama 3.2 Vision,Anthropic Claude,MQTT Writer,MoonshotAI Kimi,Google Gemini,Image Slicer,Camera Calibration,Model Comparison Visualization,Depth Estimation,Trace Visualization,Ellipse Visualization,Google Gemma,Google Gemma API,Line Counter,OPC UA Writer Sink,Slack Notification,Circle Visualization,Email Notification,LMM,Image Stack,Google Gemini,Instance Segmentation Model,Event Writer,Contrast Equalization,Camera Focus,Heatmap Visualization,Background Subtraction,Image Contours,Qwen 3.6 API,GLM-OCR,VLM As Detector,Classification Label Visualization,Bounding Box Visualization,Label Visualization,Llama 3.2 Vision,Stitch OCR Detections,Camera Focus,CSV Formatter,Stitch Images,Mask Visualization,OpenAI,SIFT,Stability AI Image Generation,Anthropic Claude,Polygon Visualization,Image Convert Grayscale - outputs:
Morphological Transformation,Image Preprocessing,Email Notification,VLM As Classifier,Morphological Transformation,Halo Visualization,Object Detection Model,Pixel Color Count,BoT-SORT Tracker,Template Matching,Image Threshold,Text Display,Pixelate Visualization,Keypoint Detection Model,Qwen-VL,OpenAI,CogVLM,Crop Visualization,SAM 3,Dot Visualization,Google Vision OCR,Florence-2 Model,Roboflow Dataset Upload,Mask Edge Snap,Qwen3.5-VL,Roboflow Vision Events,Polygon Zone Visualization,Qwen2.5-VL,Polygon Visualization,Absolute Static Crop,Twilio SMS/MMS Notification,SIFT Comparison,Contrast Enhancement,Single-Label Classification Model,OCR Model,Byte Tracker,Color Visualization,Roboflow Dataset Upload,Gaze Detection,LMM For Classification,Detections Stabilizer,Line Counter Visualization,Image Blur,Stability AI Inpainting,Object Detection Model,Blur Visualization,SAM 3,Perspective Correction,Keypoint Visualization,Anthropic Claude,MoonshotAI Kimi,Google Gemini,Image Slicer,SAM 3,Depth Estimation,Detections Stitch,Ellipse Visualization,Google Gemma API,Object Detection Model,Time in Zone,Image Stack,Google Gemini,Bounding Box Visualization,Label Visualization,Keypoint Detection Model,Camera Focus,Keypoint Detection Model,Multi-Label Classification Model,OpenAI,SIFT,Perception Encoder Embedding Model,Anthropic Claude,Image Convert Grayscale,Moondream2,OC-SORT Tracker,CLIP Embedding Model,Florence-2 Model,Seg Preview,EasyOCR,YOLO-World Model,Buffer,Multi-Label Classification Model,Segment Anything 2 Model,Single-Label Classification Model,Triangle Visualization,Icon Visualization,Qwen 3.5 API,VLM As Classifier,OpenRouter,Dominant Color,Instance Segmentation Model,Qwen3-VL,Instance Segmentation Model,OpenAI,Background Color Visualization,MoonshotAI Kimi,Google Gemini,Clip Comparison,Semantic Segmentation Model,Corner Visualization,Image Slicer,SmolVLM2,Reference Path Visualization,Single-Label Classification Model,Halo Visualization,Dynamic Crop,Instance Segmentation Model,Stability AI Outpainting,VLM As Detector,Anthropic Claude,Relative Static Crop,Multi-Label Classification Model,Clip Comparison,SORT Tracker,OpenAI,Llama 3.2 Vision,Barcode Detection,ByteTrack Tracker,Motion Detection,Camera Calibration,Google Gemma,Model Comparison Visualization,Trace Visualization,QR Code Detection,Circle Visualization,LMM,Event Writer,Instance Segmentation Model,Contrast Equalization,Camera Focus,Heatmap Visualization,Background Subtraction,Qwen 3.6 API,SAM2 Video Tracker,GLM-OCR,Image Contours,Qwen3.5,VLM As Detector,Classification Label Visualization,Llama 3.2 Vision,Stitch Images,Mask Visualization,Stability AI Image Generation,Semantic Segmentation Model,Polygon Visualization
Input and Output Bindings¶
The available connections depend on its binding kinds. Check what binding kinds
Morphological Transformation in version v2 has.
Bindings
-
input
image(image): Input color image to apply morphological transformation to. Works with BGR, BGRA, or grayscale images. Grayscale images are automatically converted to BGR for consistent color output. Transformations are applied to all channels. Output is always in color format (BGR) for compatibility with downstream blocks like Mask Edge Snap..kernel_size(integer): Size of the square structuring element (kernel) used for morphological operations. Must be a positive integer. Typical values range from 3-15. Adjust based on object sizes and desired transformation scale..operation(string): Type of morphological operation to apply. 'Opening then Closing' is specifically designed for preprocessing before edge detection and mask refinement (e.g., with Mask Edge Snap block). All other operations follow standard morphological definitions..
-
output
image(image): Image in workflows.
Example JSON definition of step Morphological Transformation in version v2
{
"name": "<your_step_name_here>",
"type": "roboflow_core/morphological_transformation@v2",
"image": "$inputs.image",
"kernel_size": "5",
"operation": "Closing"
}
v1¶
Class: MorphologicalTransformationBlockV1 (there are multiple versions of this block)
Warning: This block has multiple versions. Please refer to the specific version for details. You can learn more about how versions work here: Versioning
Apply morphological transformations to images using configurable operations (erosion, dilation, opening, closing, gradient, top hat, black hat) to modify object shapes, remove noise, fill holes, detect edges, and extract features from binary or grayscale images for image processing, noise removal, and feature extraction workflows.
How This Block Works¶
This block applies morphological transformations to images using structuring elements (kernels) to modify object shapes and extract features. The block:
- Receives an input image to transform (color images are automatically converted to grayscale)
- Converts the image to grayscale if it's in color format (morphological operations work on single-channel images)
- Creates a square structuring element (kernel) of specified kernel_size:
- Creates a square matrix of ones with dimensions (kernel_size, kernel_size)
- The kernel defines the neighborhood used for morphological operations
- Larger kernels affect larger regions, smaller kernels affect smaller regions
- Applies the selected morphological operation:
For Erosion: - Shrinks objects by removing pixels from object boundaries - Replaces each pixel with the minimum value in its kernel neighborhood - Thins objects and removes small protrusions - Useful for separating touching objects and removing small noise
For Dilation: - Expands objects by adding pixels to object boundaries - Replaces each pixel with the maximum value in its kernel neighborhood - Thickens objects and fills small holes - Useful for connecting nearby objects and filling gaps
For Opening (Erosion followed by Dilation): - First erodes then dilates the image - Removes small noise and separates touching objects - Preserves larger objects while eliminating small details - Useful for noise removal and object separation
For Closing (Dilation followed by Erosion): - First dilates then erodes the image - Fills small holes and connects nearby objects - Preserves object shape while closing gaps - Useful for filling holes and connecting fragmented objects
For Gradient (Dilation minus Erosion): - Computes the difference between dilated and eroded images - Highlights object boundaries and edges - Creates an outline effect showing object perimeters - Useful for edge detection and boundary extraction
For Top Hat (Input minus Opening): - Computes the difference between original image and its opening - Highlights small bright details that were removed by opening - Emphasizes bright features smaller than the kernel - Useful for detecting small bright objects or details
For Black Hat (Closing minus Input): - Computes the difference between closing and original image - Highlights small dark details that were filled by closing - Emphasizes dark features smaller than the kernel - Useful for detecting small dark objects or holes
- Preserves the image structure and metadata
- Returns the morphologically transformed image
Morphological operations use structuring elements (kernels) to probe and modify image structures. The kernel_size controls the scale of the transformation - larger kernels affect larger regions and have more pronounced effects. Basic operations (erosion, dilation) modify object sizes, composite operations (opening, closing) combine effects for noise removal and gap filling, and derived operations (gradient, top hat, black hat) extract specific features. The operations work best on binary or high-contrast grayscale images where object boundaries are clearly defined.
Common Use Cases¶
- Noise Removal: Remove small noise and artifacts from binary or grayscale images (e.g., remove salt-and-pepper noise, eliminate small artifacts, clean up thresholded images), enabling noise removal workflows
- Object Separation: Separate touching or overlapping objects in images (e.g., separate touching objects, split connected regions, isolate individual objects), enabling object separation workflows
- Hole Filling: Fill small holes and gaps in objects (e.g., fill holes in objects, close gaps in shapes, complete fragmented objects), enabling hole filling workflows
- Edge Detection: Detect object boundaries and edges using morphological gradient (e.g., find object edges, extract boundaries, detect object outlines), enabling morphological edge detection workflows
- Feature Extraction: Extract specific features like small bright or dark objects (e.g., detect small bright details with top hat, find small dark objects with black hat, extract specific morphological features), enabling feature extraction workflows
- Image Preprocessing: Prepare binary or grayscale images for further processing (e.g., clean up thresholded images, prepare images for contour detection, preprocess images for analysis), enabling morphological preprocessing workflows
Connecting to Other Blocks¶
This block receives an image and produces a morphologically transformed image:
- After image thresholding blocks to clean up thresholded binary images (e.g., remove noise from thresholded images, fill holes in binary images, separate objects in thresholded images), enabling thresholding-to-morphology workflows
- After preprocessing blocks to apply morphological operations after other preprocessing (e.g., apply morphology after filtering, clean up after thresholding, process after enhancement), enabling multi-stage preprocessing workflows
- Before contour detection blocks to prepare images for contour detection (e.g., clean up images before contour detection, fill holes before finding contours, separate objects before contour analysis), enabling morphology-to-contour workflows
- Before analysis blocks that process binary or grayscale images (e.g., analyze cleaned images, process separated objects, work with morphologically processed images), enabling morphological analysis workflows
- Before visualization blocks to display morphologically transformed images (e.g., visualize cleaned images, display processed results, show transformation effects), enabling morphological visualization workflows
- In image processing pipelines where morphological operations are part of a larger processing chain (e.g., clean images in pipelines, apply morphology in multi-stage workflows, process images in transformation chains), enabling morphological processing pipeline workflows
Requirements¶
This block works on single-channel (grayscale) images. Color images are automatically converted to grayscale before processing. Morphological operations work best on binary or high-contrast grayscale images where object boundaries are clearly defined. For optimal results, use thresholded binary images or high-contrast grayscale images as input.
Type identifier¶
Use the following identifier in step "type" field: roboflow_core/morphological_transformation@v1to add the block as
as step in your workflow.
Properties¶
| Name | Type | Description | Refs |
|---|---|---|---|
name |
str |
Enter a unique identifier for this step.. | ❌ |
kernel_size |
int |
Size of the square structuring element (kernel) used for morphological operations. Must be a positive integer. The kernel is a square matrix of ones with dimensions (kernel_size, kernel_size). Larger values create larger kernels that affect larger regions and produce more pronounced effects. Smaller values create smaller kernels that affect smaller regions with subtler effects. Typical values range from 3-15: smaller values (3-5) for fine operations and small objects, medium values (5-9) for general use, larger values (11-15) for coarse operations and large objects. Default is 5, which provides a good balance. Adjust based on object sizes and desired transformation scale.. | ✅ |
operation |
str |
Type of morphological operation to apply: 'Erosion' shrinks objects by removing boundary pixels (separates objects, removes noise), 'Dilation' expands objects by adding boundary pixels (connects objects, fills holes), 'Opening' (erosion then dilation) removes noise and separates objects, 'Closing' (default, dilation then erosion) fills holes and connects objects, 'Gradient' (dilation minus erosion) finds object boundaries/edges, 'Top Hat' (input minus opening) detects small bright details, or 'Black Hat' (closing minus input) detects small dark details. Default is 'Closing' which is commonly used for hole filling. Choose based on goals: erosion/dilation for size modification, opening/closing for noise removal and gap filling, gradient for edge detection, top hat/black hat for feature extraction.. | ✅ |
The Refs column marks possibility to parametrise the property with dynamic values available
in workflow runtime. See Bindings for more info.
Available Connections¶
Compatible Blocks
Check what blocks you can connect to Morphological Transformation in version v1.
- inputs:
Morphological Transformation,Roboflow Asset Library Attributes,Image Preprocessing,Florence-2 Model,Email Notification,VLM As Classifier,Halo Visualization,Morphological Transformation,EasyOCR,Pixel Color Count,Object Detection Model,Text Display,Template Matching,Image Threshold,Twilio SMS Notification,Local File Sink,Icon Visualization,Triangle Visualization,Qwen 3.5 API,Model Monitoring Inference Aggregator,Pixelate Visualization,Keypoint Detection Model,Microsoft SQL Server Sink,Qwen-VL,OpenAI,CogVLM,Crop Visualization,Dot Visualization,Google Vision OCR,OpenRouter,Florence-2 Model,Roboflow Dataset Upload,Distance Measurement,Qwen3.5-VL,Roboflow Vision Events,Polygon Zone Visualization,Polygon Visualization,OpenAI,SIFT Comparison,Background Color Visualization,Absolute Static Crop,S3 Sink,MoonshotAI Kimi,Twilio SMS/MMS Notification,QR Code Generator,SIFT Comparison,Contrast Enhancement,Google Gemini,Grid Visualization,Corner Visualization,Reference Path Visualization,Image Slicer,Single-Label Classification Model,Stitch OCR Detections,Line Counter,Halo Visualization,Dynamic Crop,Webhook Sink,OCR Model,Color Visualization,Stability AI Outpainting,Detection Event Log,Roboflow Dataset Upload,Roboflow Custom Metadata,LMM For Classification,OpenAI-Compatible LLM,Relative Static Crop,Image Blur,Line Counter Visualization,Stability AI Inpainting,Blur Visualization,Anthropic Claude,Clip Comparison,Multi-Label Classification Model,Current Time,OpenAI,Perspective Correction,Keypoint Visualization,Llama 3.2 Vision,Anthropic Claude,MQTT Writer,MoonshotAI Kimi,Google Gemini,Image Slicer,Camera Calibration,Model Comparison Visualization,Depth Estimation,Trace Visualization,Ellipse Visualization,Google Gemma,Google Gemma API,Line Counter,OPC UA Writer Sink,Slack Notification,Circle Visualization,Email Notification,LMM,Image Stack,Google Gemini,Instance Segmentation Model,Event Writer,Contrast Equalization,Camera Focus,Heatmap Visualization,Background Subtraction,Image Contours,Qwen 3.6 API,GLM-OCR,VLM As Detector,Classification Label Visualization,Bounding Box Visualization,Label Visualization,Llama 3.2 Vision,Stitch OCR Detections,Camera Focus,CSV Formatter,Stitch Images,Mask Visualization,OpenAI,SIFT,Stability AI Image Generation,Anthropic Claude,Polygon Visualization,Image Convert Grayscale - outputs:
Morphological Transformation,Image Preprocessing,Email Notification,VLM As Classifier,Morphological Transformation,Halo Visualization,Object Detection Model,Pixel Color Count,BoT-SORT Tracker,Template Matching,Image Threshold,Text Display,Pixelate Visualization,Keypoint Detection Model,Qwen-VL,OpenAI,CogVLM,Crop Visualization,SAM 3,Dot Visualization,Google Vision OCR,Florence-2 Model,Roboflow Dataset Upload,Mask Edge Snap,Qwen3.5-VL,Roboflow Vision Events,Polygon Zone Visualization,Qwen2.5-VL,Polygon Visualization,Absolute Static Crop,Twilio SMS/MMS Notification,SIFT Comparison,Contrast Enhancement,Single-Label Classification Model,OCR Model,Byte Tracker,Color Visualization,Roboflow Dataset Upload,Gaze Detection,LMM For Classification,Detections Stabilizer,Line Counter Visualization,Image Blur,Stability AI Inpainting,Object Detection Model,Blur Visualization,SAM 3,Perspective Correction,Keypoint Visualization,Anthropic Claude,MoonshotAI Kimi,Google Gemini,Image Slicer,SAM 3,Depth Estimation,Detections Stitch,Ellipse Visualization,Google Gemma API,Object Detection Model,Time in Zone,Image Stack,Google Gemini,Bounding Box Visualization,Label Visualization,Keypoint Detection Model,Camera Focus,Keypoint Detection Model,Multi-Label Classification Model,OpenAI,SIFT,Perception Encoder Embedding Model,Anthropic Claude,Image Convert Grayscale,Moondream2,OC-SORT Tracker,CLIP Embedding Model,Florence-2 Model,Seg Preview,EasyOCR,YOLO-World Model,Buffer,Multi-Label Classification Model,Segment Anything 2 Model,Single-Label Classification Model,Triangle Visualization,Icon Visualization,Qwen 3.5 API,VLM As Classifier,OpenRouter,Dominant Color,Instance Segmentation Model,Qwen3-VL,Instance Segmentation Model,OpenAI,Background Color Visualization,MoonshotAI Kimi,Google Gemini,Clip Comparison,Semantic Segmentation Model,Corner Visualization,Image Slicer,SmolVLM2,Reference Path Visualization,Single-Label Classification Model,Halo Visualization,Dynamic Crop,Instance Segmentation Model,Stability AI Outpainting,VLM As Detector,Anthropic Claude,Relative Static Crop,Multi-Label Classification Model,Clip Comparison,SORT Tracker,OpenAI,Llama 3.2 Vision,Barcode Detection,ByteTrack Tracker,Motion Detection,Camera Calibration,Google Gemma,Model Comparison Visualization,Trace Visualization,QR Code Detection,Circle Visualization,LMM,Event Writer,Instance Segmentation Model,Contrast Equalization,Camera Focus,Heatmap Visualization,Background Subtraction,Qwen 3.6 API,SAM2 Video Tracker,GLM-OCR,Image Contours,Qwen3.5,VLM As Detector,Classification Label Visualization,Llama 3.2 Vision,Stitch Images,Mask Visualization,Stability AI Image Generation,Semantic Segmentation Model,Polygon Visualization
Input and Output Bindings¶
The available connections depend on its binding kinds. Check what binding kinds
Morphological Transformation in version v1 has.
Bindings
-
input
image(image): Input image to apply morphological transformation to. Color images are automatically converted to grayscale before processing (morphological operations work on single-channel images). Works best on binary or high-contrast grayscale images where object boundaries are clearly defined. Thresholded binary images produce optimal results. The morphologically transformed image will have modified object shapes, removed noise, filled holes, or extracted features depending on the selected operation. Original image metadata is preserved in the output..kernel_size(integer): Size of the square structuring element (kernel) used for morphological operations. Must be a positive integer. The kernel is a square matrix of ones with dimensions (kernel_size, kernel_size). Larger values create larger kernels that affect larger regions and produce more pronounced effects. Smaller values create smaller kernels that affect smaller regions with subtler effects. Typical values range from 3-15: smaller values (3-5) for fine operations and small objects, medium values (5-9) for general use, larger values (11-15) for coarse operations and large objects. Default is 5, which provides a good balance. Adjust based on object sizes and desired transformation scale..operation(string): Type of morphological operation to apply: 'Erosion' shrinks objects by removing boundary pixels (separates objects, removes noise), 'Dilation' expands objects by adding boundary pixels (connects objects, fills holes), 'Opening' (erosion then dilation) removes noise and separates objects, 'Closing' (default, dilation then erosion) fills holes and connects objects, 'Gradient' (dilation minus erosion) finds object boundaries/edges, 'Top Hat' (input minus opening) detects small bright details, or 'Black Hat' (closing minus input) detects small dark details. Default is 'Closing' which is commonly used for hole filling. Choose based on goals: erosion/dilation for size modification, opening/closing for noise removal and gap filling, gradient for edge detection, top hat/black hat for feature extraction..
-
output
image(image): Image in workflows.
Example JSON definition of step Morphological Transformation in version v1
{
"name": "<your_step_name_here>",
"type": "roboflow_core/morphological_transformation@v1",
"image": "$inputs.image",
"kernel_size": "5",
"operation": "Closing"
}