Gadgets 4 Students Career Guide Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
1.7k views
in OpenCV (Open Source Computer Vision Library) by Goeduhub's Expert (9.3k points)
Morphological Operations-Erosion and Dilation in Opencv Python

1 Answer

0 like 0 dislike
by Goeduhub's Expert (9.3k 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()

Limited Time Offer (till 09/09/2020):- Free Online 5.13 HRS long Course on Computer Vision with OpenCV | Deep Learning CNN Projects:- Apply Coupon

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory
...