简体   繁体   中英

erode/dilte - without shifting the image downwards

I eroded an image and then dilated it.

im = cv.erode(im, (7,7), iterations=5)
im = cv.dilate(im, (7,7), iterations=5)

This is the original images

在此处输入图片说明

And this is the eroded-then-dilated image

在此处输入图片说明

I tried to remove the small portion on the top-right of the original image which was removed properly. But the new image is shifted slightly downward compared to the original image. Is there any way to erode and dilate without shifting the image downward?

Finally fixed it. It was easy. Just rotated the image 180 degrees before dilating again. Then rotated it 180 degrees again after dilation

Your code should not have worked at all. Your second argument is wrong. It must be a kernel (2D array), not the size of the kernel.

Simply pass None there. That will assume a simple 3x3 box kernel. Then work with the iterations argument.

You should work more closely with the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM