-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorphology.py
39 lines (27 loc) · 872 Bytes
/
morphology.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import cv2 as cv
img = cv.imread('lena.jpg')
element = cv.getStructuringElement(cv.MORPH_RECT,(5,5))
erode_img = cv.erode(img, element)
dilate_img = cv.dilate(img,element)
cv.imshow('original',img)
cv.imshow('erode_img',erode_img)
cv.imshow('dilate_img',dilate_img)
cv.waitKey(0)
#other morphology operation:
#open:
open_img = cv.morphologyEx(img,cv.MORPH_OPEN,element)
cv.imshow('open',open_img)
#close:
close_img = cv.morphologyEx(img,cv.MORPH_CLOSE,element)
cv.imshow('close',close_img)
#grad:
grad_img = cv.morphologyEx(img,cv.MORPH_GRADIENT,element)
cv.imshow('grad',grad_img)
#tophat:
tophat_img = cv.morphologyEx(img,cv.MORPH_TOPHAT,element)
cv.imshow('tophat',tophat_img)
#backhat:
backhatp_img = cv.morphologyEx(img,cv.MORPH_BLACKHAT,element)
cv.imshow('backhat',backhatp_img)
cv.waitKey(0)
cv.destroyAllWindows()