[190216][opencv] getStructuringElement()

一、Prototype

Mat cv::getStructuringElement 	( 	int  	shape,
									Size  	ksize,
									Point  	anchor = Point(-1,-1) 
	) 	

returns a structuring element of the specified size and shape for morphological operations.
the function constructs and returns the structuring element that can be further passed to erode, dilate or morphologyEx. but you can also construct an arbitrary binary mask yourself and use it as the structuring element.

Parameters
shape Element shape that could be one of MorphShapes
ksize Size of the structuring element.
anchor Anchor position within the element. The default value (−1,−1) means that the anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor position. In other cases the anchor just regulates how much the result of the morphological operation is shifted.

二、Demo

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
	Mat element;
	element = getStructuringElement(MORPH_ELLIPSE, Size(100, 100));
	//other parameters: element = getStructuringElement(...,Size(..., ...));
	cout << element;
	return 0;
}

三、Result

1/element = getStructuringElement(MORPH_ELLIPSE, Size(100, 100));
copy the result to an Excel file and find out its shape is an ellipse, the picture is as follow:
figure1note: 1/(about the picture) i don’t know why there is a yellow block at the right bottom after i check the settings in Excel which turns out to be no wrong.
2/the shape of ellipse is not so obvious when the second parameter is set small. i.e.

element = getStructuringElement(MORPH_ELLIPSE, Size(5, 5));

result:
[ 0, 0, 1, 0, 0;
1, 1, 1, 1, 1;
1, 1, 1, 1, 1;
1, 1, 1, 1, 1;
0, 0, 1, 0, 0]
2/element = getStructuringElement(MORPH_CROSS, Size(4, 4));
result:
[ 0, 0, 1, 0;
0, 0, 1, 0;
1, 1, 1, 1;
0, 0, 1, 0]

element = getStructuringElement(MORPH_CROSS, Size(5, 5));

result:
[ 0, 0, 1, 0, 0;
0, 0, 1, 0, 0;
1, 1, 1, 1, 1;
0, 0, 1, 0, 0;
0, 0, 1, 0, 0]

element = getStructuringElement(MORPH_CROSS, Size(6, 6));

result:
[ 0, 0, 0, 1, 0, 0;
0, 0, 0, 1, 0, 0;
0, 0, 0, 1, 0, 0;
1, 1, 1, 1, 1, 1;
0, 0, 0, 1, 0, 0;
0, 0, 0, 1, 0, 0]

note:1/when the dimension of ‘element’ is odd, the crossing begins at the row/col whose index is (dimension/2 + 1).
3/element = getStructuringElement(MORPH_RECT, Size(5, 5));
result:
[ 1, 1, 1, 1, 1;
1, 1, 1, 1, 1;
1, 1, 1, 1, 1;
1, 1, 1, 1, 1;
1, 1, 1, 1, 1]
note:1/quite obvious, nothing to analyze.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: `cv2.getStructuringElement()` 是 OpenCV 库中的一个函数,用于创建形态学操作中使用的结构元素。该函数的语法如下: ```python cv2.getStructuringElement(shape, ksize[, anchor]) ``` 其中,`shape` 参数指定了结构元素的形状,可以是以下值之一: - `cv2.MORPH_RECT`:矩形结构元素 - `cv2.MORPH_CROSS`:十字形结构元素 - `cv2.MORPH_ELLIPSE`:椭圆形结构元素 `ksize` 参数指定了结构元素的大小,为一个二元组 `(w, h)`,其中 `w` 和 `h` 分别表示结构元素的宽度和高度。 `anchor` 参数是可选的,指定了结构元素的锚点位置,即结构元素中心的位置。如果不指定,则默认为结构元素的中心位置。 该函数的返回值是一个 numpy 数组,表示生成的结构元素。 ### 回答2: OpenCV中getstructuringelement是一个函数,用于生成指定形状和大小的结构元素(kernel)。结构元素是影响图像形态学操作(如腐蚀和膨胀)的一种模板。getstructuringelement接受三个参数,分别是结构元素的形状、大小和锚点位置。 形状(shape)参数可以是一个整数或一个OpenCV定义的枚举类型。常见的形状包括矩形(RECTANGLE)、十字形(CROSS)和椭圆形(ELLIPSE)等,通过设置不同的形状可以获得不同的结构元素。 大小(size)参数是结构元素的大小,由两个整数表示。大小的长和宽必须是奇数,因为结构元素必须有中心点。结构元素的大小影响操作的效果,较小的元素会产生较强的效果,但也可以增加计算开销。 锚点(anchor)参数表示结构元素的中心点。默认值为(-1,-1),表示将中心点设置为结构元素的几何中心。锚点的位置可用于控制操作的起点和方向。 getstructuringelement的返回值是一个Mat对象,代表了生成的结构元素。结构元素是一个二值矩阵,元素值为0或1。在进行形态学操作时,结构元素会被用于与图像中的像素进行比较,产生操作的效果。 getstructuringelementOpenCV形态学操作中的一个重要函数,能通过生成不同形状、大小和锚点位置的结构元素,实现不同的效果。在应用中,我们可以尝试根据实际需求生成不同的结构元素,达到更好的操作效果。 ### 回答3: OpenCV是一个广泛应用于计算机视觉的开源计算机视觉库。它包含了数百个用于图像处理,计算机视觉以及机器学习的函数。getstructuringelement是这个库内的一个函数,它用于获取指定形状和大小的结构元素(structuring element)。 结构元素是一种在图像分析中广泛使用的概念。它是一个小的形状,可以被用来扫描图像中的区域,从而进行一些形态学操作,如膨胀、腐蚀、开运算、闭运算等。 getstructuringelement函数是用来创建这样的结构元素。这个函数有两个参数:shape和ksize。其中,shape参数可以取如下值: * MORPH_RECT(矩形结构元素) * MORPH_CROSS(十字形结构元素) * MORPH_ELLIPSE(椭圆形结构元素) ksize参数则指定了创建的结构元素的大小。这个参数应该是一个大小为大于1的奇数。 函数的返回值是一个和指定形状和大小的结构元素。这个返回的值可以被传递到其他形态学函数中,用于进行像素处理操作。 总之,getstructuringelement函数是OpenCV库内用于创建结构元素的函数。它的输入是形状和大小,输出是得到的结构元素(structuring element)的矩阵,这个矩阵可以被传递到其他形态学运算函数中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值