Add Support for Diamond-Shaped Structuring Element in Morphological Operations #27441
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Overview
This PR introduces support for a new diamond-shaped structuring element in OpenCV’s morphology module. The addition enables users to perform morphological operations (e.g., erosion, dilation, opening, closing) using a diamond-shaped kernel, which is defined by Manhattan distance from the center.
Detailed Changes
Motivation
Diamond-shaped structuring elements are widely used in image processing, particularly where neighborhood connectivity is defined by Manhattan distance (e.g., certain denoising, thinning, or skeletonization tasks). By supporting this shape natively, OpenCV expands its flexibility and applicability to new classes of problems.
Backward Compatibility
This change is fully backward compatible and does not alter any existing functionality or APIs. It only adds a new option for kernel shape selection.
Usage Example
cv::Mat diamondKernel = cv::getStructuringElement(cv::MORPH_DIAMOND, cv::Size(5, 5));
Testing
Checklist
Added new enum values for the diamond shape.
Implemented diamond kernel logic in morphology dispatch.
Closing
This PR fills a gap in OpenCV’s morphological toolkit by providing a commonly-used structuring element. Please let me know if further changes or documentation are needed.