/形态学操作-膨胀 Mat struct1, struct2; struct1 = getStructuringElement(0, Size(3, 3)); //矩形结构元素 struct2 = getStructuringElement(1, Size(3, 3)); //十字结构元素 Mat dilateGray, dilateGray1; dilate(gray1, dilateGray, struct1, Point(-1, -1), 1); dilate(gray1, dilateGray1, struct2, Point(-1, -1), 2); imshow("dilateGray", dilateGray); imshow("erodeGray1", dilateGray1);
时间: 2023-07-16 08:11:30 浏览: 26
这段代码实现了图像的膨胀操作,使用的是OpenCV库中的函数。首先,通过getStructuringElement函数获取两个不同的结构元素,一个是3x3的矩形结构元素(struct1),另一个是3x3的十字结构元素(struct2)。然后,分别对输入的灰度图像gray1进行两次膨胀操作,第一次使用矩形结构元素,膨胀程度为1,得到结果dilateGray;第二次使用十字结构元素,膨胀程度为2,得到结果dilateGray1。最后,使用imshow函数显示膨胀后的图像。
相关问题
//形态学操作-膨胀 Mat struct1, struct2; struct1 = getStructuringElement(0, Size(3, 3)); //矩形结构元素 struct2 = getStructuringElement(1, Size(3, 3)); //十字结构元素 Mat dilateGray, dilateGray1; dilate(gray1, dilateGray, struct1, Point(-1, -1), 1); dilate(gray1, dilateGray1, struct2, Point(-1, -1), 2); imshow("dilateGray", dilateGray); imshow("erodeGray1", dilateGray1);
这段代码使用了OpenCV库的形态学操作函数,其中包括了膨胀操作。首先定义了两个结构元素struct1和struct2,分别对应矩形和十字形结构元素。然后使用dilate函数对灰度图像进行膨胀操作,其中第一个参数是输入图像,第二个参数是输出图像,第三个参数是结构元素,第四个参数是锚点位置,第五个参数是迭代次数。最后使用imshow函数显示膨胀后的图像。
//形态学操作-腐蚀 Mat erodeGray, erodeGray1; Mat struct3, struct4; struct3 = getStructuringElement(0, Size(3, 3)); //矩形结构元素 struct4 = getStructuringElement(1, Size(3, 3)); //十字结构元素 erode(dilateGray, erodeGray, struct3, Point(-1, -1), 3); erode(dilateGray, erodeGray1, struct4, Point(-1, -1), 3); imshow("erodeGray", erodeGray); imshow("erodeGray1", erodeGray1); Mat edge; Canny(erodeGray, edge, 80, 180, 3, false); //imshow("edge",edge);
这段代码是对图像进行形态学操作中的腐蚀操作。首先定义了两个矩阵结构元素,一个是3x3的矩形结构元素,另一个是3x3的十字结构元素。然后分别使用这两个结构元素对输入图像dilateGray进行腐蚀操作,得到两个输出图像erodeGray和erodeGray1。最后使用Canny算子对erodeGray进行边缘检测,得到输出图像edge。其中Canny算子的参数80和180分别表示边缘检测时的低阈值和高阈值,3表示Sobel算子的大小,false表示不使用L2梯度计算。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)