Winter Bootcamp in ML and IoT in Jaipur
 Course content (For Bootcamp & Winter Training):- Machine Learning (ML) || Internet of Things (IoT) || Register for winter bootcamp
0 like 0 dislike
in Examples, Exercises and Projects by (3.2k points)

1 Answer

0 like 0 dislike
by (3.2k points)
 
Best answer

Erosion and Dilation are Morphological Operations
Erosion: Removes pixels at the boundaries of objects in an image
Dilation: Adds pixels to the boundaries of objects in an image

# Import Computer Vision package - cv2
import cv2

# Import Numerical Python package - numpy as np
import numpy as np

# Read the image using imread built-in function
image = cv2.imread('image_7.jpg')

# Display original image using imshow built-in function
cv2.imshow("Original", image)

# Wait until any key is pressed
cv2.waitKey(0)

# np.ones returns an array, given shape and type, filled with ones
# np.ones(shape, dtype)
kernel = np.ones((5,5), dtype = "uint8")
# here 5 x 5 is the dimension of the kernal
# uint8: is an unsigned integer (0 to 255)

# cv2.erode is the built-in function used for erosion

# cv2.erode(image, kernel, iterations)
erosion = cv2.erode(image, kernel, iterations = 1)

# Display image after erosion using imshow built-in function
cv2.imshow("Erosion", erosion)

# Wait until any key is pressed
cv2.waitKey(0)

# cv2.dilate is the built-in function used for dilation

# cv2.dilate(image, kernel, iterations)
dilation = cv2.dilate(image, kernel, iterations = 1)

# Display image after dilation using imshow built-in function
cv2.imshow("Dilation", dilation)

# Wait until any key is pressed
cv2.waitKey(0)

# Close all windows
cv2.destroyAllWindows()

Winter 10 Days bootcamp classes(7 HRS Daily) will start from 5 & 20 December 2019 in:
1) Internet of things(IoT) Using RASPBERRY-PI
2) Machine Learning (ML)

70% OFF| Fee-INR 3,000/-

Limited seats!! Hurry up!!

[[ CALL - 07976731765 ]]

Some Study Resources are compiled from original Stack Overflow Documentation, the content is developed by the different experts at Stack Overflow. Study resources are released under Creative Commons BY-SA. Images may be copyright of their respective owners. This website is for self-learning and not affiliated with Stack Overflow. All trademarks and registered trademarks are the property of their respective company owners. Please send feedback and corrections to chandwaglobal@gmail.com.

...