Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disk Structuring Element opencv vs Matlab

I want to create a disk shaped structuring element on OpenCv. I need my SE to be similar with

sel = strel('disk',5);

I want to do this using

cvstructuringElementEx(cols,rows,anchor_x,anchor_y,shape,*values);

What do I need to do to achieve this and which values of anchor_x and anchor_y give the same center point of SE with MATLAB?

like image 995
Muhammet Ali Asan Avatar asked Jun 22 '13 13:06

Muhammet Ali Asan


1 Answers

According to the docs, you could try:

cv::Mat sel = cv::getStructuringElement(MORPH_ELLIPSE, cv::Size(9,9));

This gave me the following structuring element:

0    0    0    0    1    0    0    0    0
0    1    1    1    1    1    1    1    0
0    1    1    1    1    1    1    1    0
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    1    1
0    1    1    1    1    1    1    1    0
0    1    1    1    1    1    1    1    0
0    0    0    0    1    0    0    0    0

While in MATLAB I got:

>> getnhood(strel('disk',5))
ans =
     0     0     1     1     1     1     1     0     0
     0     1     1     1     1     1     1     1     0
     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     1     1
     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1
     0     1     1     1     1     1     1     1     0
     0     0     1     1     1     1     1     0     0

So not exactly the same but close enough :)

like image 174
Amro Avatar answered Sep 20 '22 08:09

Amro