Summer training at Goeduhub Technologies-Jaipur

Online Instructor-Led Live Training Courses/Workshops details

0 like 0 dislike
112 views
in Examples, Exercises and Projects by Goeduhub's Expert (7.3k points)

1 Answer

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

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
 Know About Popular Colleges/Universities  List of IITsList of NITs | RTU-KOTA/BTU-Bikaner | Manipal University-Jaipur | JECRC University | Amity University Jaipur | BIT Mesra-Jaipur | MODY UNIVERSITY | LNMIIT-Jaipur | JK Lakshmipat | Banasthali Vidyapith | POORNIMA University
 Exams:   List of Exams After Graduation | List of Engineering Entrance Examinations (UG/PG) | JEE Main | JEE Advanced | GATE | IES | ISROList of PSUs
Placements:  List of companies | Logical Reasoning Questions | Quantitative Aptitude Questions | General English Questions | Technical-MCQ and Interview Questions
 Download Previous Year Papers For:  GATE | IES | RAJASTHAN TECHNICAL UNIVERSITY (RTU-Kota)RPSC Technical Exams | ISRO
 Online Free Training:  Artificial Intelligence(AI) & Machine Learning(ML)Python Programming | Internet of Things-IoT | OpenCV (Open Source Computer Vision Library) | LINUX | Big Data : Hadoop | 
 Goeduhub
About Us | Contact Us   Social::   |  | 
...