Create structuring element for morphological operations - getStructuringElement
ShahBaz | سه شنبه, ۹ شهریور ۱۳۹۵، ۱۰:۰۱ ق.ظ
Create structuring element for morphological operations
Mat getStructuringElement(int shape, Size ksize, Point anchor=Point(-1,-1))
Parameters:
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 the following:
- MORPH_RECT (0) - a rectangular structuring element:
- MORPH_ELLIPSE (2) - an elliptic structuring element, that is, a filled ellipse inscribed into the rectangle Rect(0, 0, esize.width, esize.height)
- MORPH_CROSS (1)- a cross-shaped structuring element:
- CV_SHAPE_CUSTOM (100) - custom structuring element (OpenCV 1.x API)
- ksize – Size of the structuring element.
- cols – Width of the structuring element
- rows – Height 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.
You can also construct an arbitrary binary mask yourself and use it as the structuring element.
Example:
--------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace cv;
using namespace std;
int main()
{ // Create a structuring element (SE)
int morph_size = 3;
Mat element = getStructuringElement( MORPH_ELLIPSE, Size( 4*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
cout<<element;
return 0;
} |
--------