# Can cv2.dilate using with even kernel like 2x2 or 4x4?

Is that possible doing dilation with even kernel in cv2.dilate?

Can cv2.dilate using with even kernel like 2x2 or 4x4?

Is that possible doing dilation with even kernel in cv2.dilate?

add a comment

0

Best way is to test

```
m=imread("f:/lib/opencv/samples/data/fruits.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat m2=Mat::ones(2,2,CV_8U);
Mat m3=Mat::ones(3,3,CV_8U);
Matdst2,dst3,dst;
dilate(m,dst2,m2);
dilate(m,dst3,m3);
subtract(dst2,dst3,dst,Mat(),CV_16S);
float x = norm(dst);
cout<<"Difference between erode 2x2 and 3x3 : "<<x;
```

the difference is 4337.25 and for anchor (ksize = 2 or 3 in my example and anchor.x==-1) line 357 filterengine.hpp opencv 3.0

```
if( anchor.x == -1 )
anchor.x = ksize.width/2;
if( anchor.y == -1 )
anchor.y = ksize.height/2;
```

@LBerger I'm sorry there is mistake when I writing the code, it's giving different result now, but I'm still confuse the anchor `x,y value`

. If `default value=(-1,-1)`

and I use kernel 2x2 so the `anchor x,y=1`

, so it's mean the origin is in bottom right for kernel 2x2 isn't it?

If Iterations value is 25 itmeans that you are going to make 25 dilate. But in opencv source code at line 1698 you can find that image is dilated only once. But operator is resize 25 times in function getStructuringElement at line 1028 . Of course results are similar. In that case you must pay attention to border value.Hence Limit is relative to source image size something like max(height,rows) of source image divide size of structuring element

PS I hope that my reading is good may be you should check it if you have a specific ned for dilate

Asked: **
2015-06-26 14:14:41 -0500
**

Seen: **759 times**

Last updated: **Jun 27 '15**

Memory leak with morphological operators

opencv python - recognizing and identify coins

Mat_<uchar> translation in java, dilating

What type of gpuMat is needed for gpu version of erode function?

Erosion / Dilation erroneous output for empty structuring element?

difference between blur and dilate

Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.