形态学操作
形态学操作就是基于形状的一些列图像处理操作。通过结构元素作用于输入图像产生输出图像。
结构元素,就是形态学操作的处理内核。通过内核与图像的卷积完成处理过程。内核可以有各种形状如矩形,圆形,菱形。结构元素的锚点(即与处理元素重合的点)默认为中心(参数cv::Point()-1,-1).opencv一般默认3*3的结构元素,我们也可以自己定义1,3,5,7尺寸的结构元素。例如定义一个7*7的cv::Mat element(7,7,CV_8U,Scalar(1)).
一般情况下形态学操作针对的是单通道图。
最基本的形态学操作有二:腐蚀与膨胀(Erosion 与 Dilation)。 他们的运用广泛:
消除噪声
分割(isolate)独立的图像元素,以及连接(join)相邻的元素。
寻找图像中的明显的极大值区域或极小值区域。
cv::dilate(cornerStrength,dilated,cv::Mat());
cv::compare(cornerStrength,dilataed,localMax,cv::CMP_EQ);
利用膨胀是用最大值替换的原则,只有最大值不变,将区域中的最大值位置提取出来
膨胀腐蚀是针对较大的元素而言的,故膨胀是亮色的膨胀(暗色腐蚀),腐蚀是亮色的腐蚀(暗色膨胀)
void erode (const Mat& src, Mat& dst, const Mat& element, Point anchor=Point(-1, -1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue() ) ¶
Erodes an image by using a specific structuring element.
Parameters: |
|
---|
The function erodes the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the minimum is taken:
The function supports the in-place mode. Erosion can be applied several ( iterations ) times. In the case of multi-channel images each channel is processed independently.
-
void
erode
(const
Mat&
src,
Mat&
dst, const
Mat&
element, Point
anchor=Point(-1, -1), int
iterations=1, int
borderType=BORDER_CONSTANT, const Scalar&
borderValue=morphologyDefaultBorderValue()
)
¶
-
Erodes an image by using a specific structuring element.
Parameters: - src – The source image
- dst – The destination image. It will have the same size and the same type as src
- element – The structuring element used for dilation. If element=Mat() , a rectangular structuring element is used
- anchor – Position of the anchor within the element. The default value means that the anchor is at the element center
- iterations – The number of times erosion is applied
- borderType – The pixel extrapolation method; see borderInterpolate()
- borderValue – The border value in case of a constant border. The default value has a special meaning, see createMorphoogyFilter()
The function erodes the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the minimum is taken:
The function supports the in-place mode. Erosion can be applied several ( iterations ) times. In the case of multi-channel images each channel is processed independently.