Performs advanced morphological transformations.
-
C++:
void
morphologyEx
(InputArray
src, OutputArray
dst, int
op, InputArray
kernel, Point
anchor=Point(-1,-1), int
iterations=1, int
borderType=BORDER_CONSTANT, const Scalar&
borderValue=morphologyDefaultBorderValue()
)
-
-
Python:
cv2.
morphologyEx
(src, op, kernel
[, dst
[, anchor
[, iterations
[, borderType
[, borderValue
]
]
]
]
]
) → dst
-
-
C:
void
cvMorphologyEx
(const CvArr*
src, CvArr*
dst, CvArr*
temp, IplConvKernel*
element, int
operation, int
iterations=1
)
-
-
Python:
cv.
MorphologyEx
(src, dst, temp, element, operation, iterations=1
) → None
-
Parameters: - src – Source image. The number of channels can be arbitrary. The depth should be one of CV_8U, CV_16U, CV_16S, CV_32F` or ``CV_64F.
- dst – Destination image of the same size and type as src .
- element – Structuring element.
- op –
Type of a morphological operation that can be one of the following:
- MORPH_OPEN - an opening operation
- MORPH_CLOSE - a closing operation
- MORPH_GRADIENT - a morphological gradient
- MORPH_TOPHAT - “top hat”
- MORPH_BLACKHAT - “black hat”
- iterations – Number of times erosion and dilation are applied.
- borderType – Pixel extrapolation method. See borderInterpolate() for details.
- borderValue – Border value in case of a constant border. The default value has a special meaning. See createMorphologyFilter() for details.
The function can perform advanced morphological transformations using an erosion and dilation as basic operations.
Opening operation:
Closing operation:
Morphological gradient:
“Top hat”:
“Black hat”:
Any of the operations can be done in-place. In case of multi-channel images, each channel is processed independently.
See also
Note
- An example using the morphologyEx function for the morphological opening and closing operations can be found at opencv_source_code/samples/cpp/morphology2.cpp