O'Reilly logo

Computer Vision with Python 3 by Saurabh Kapur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Erosion

As we saw in the earlier chapter, erosion requires a structuring element or kernel; therefore, the erode() function in OpenCV requires an image, kernel, and the number of times the erosion should be applied as input. Let's see an example code:

>>> import cv2>>> import numpy as np>>> img = cv2.imread("thresholding.jpg")>>> ker = np.ones((5,5),np.uint8)>>> new_img = cv2.erode(img,ker,iterations = 1)>>> cv2.imwrite("erosion.jpg", new_img)>>> cv2.imshow("erosion", new_img)

The following figure shows the output of the code:

Figure 11: The input image is on the left and the image on the right is the output

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required