-
Notifications
You must be signed in to change notification settings - Fork 0
/
morphologicalTransforms.py
67 lines (42 loc) · 1.99 KB
/
morphologicalTransforms.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys
import cv2
import numpy as np
## ------------ ALL MORPHOLOGICAL FILTERS ------------- ##
# Morph Helper Function is in main due to shared resources with the class!
def dilate(self):
self.morphTransformHelper('dilate')
kernel = np.ones((self.slider.value(), self.slider.value()), np.uint8)
self.processedImage = cv2.dilate(self.processedImage, kernel, iterations=1)
self.displayImage(2)
def erode(self):
self.morphTransformHelper('erode')
kernel = np.ones((5, 5), np.uint8)
self.processedImage = cv2.erode(self.processedImage, kernel, iterations=1)
self.displayImage(2)
def opening(self):
self.morphTransformHelper('opening')
kernel = np.ones((self.slider.value(), self.slider.value()), np.uint8)
self.processedImage = cv2.morphologyEx(self.processedImage, cv2.MORPH_OPEN, kernel)
self.displayImage(2)
def closing(self):
self.morphTransformHelper('closing')
self.processedImage = self.originalImage.copy()
kernel = np.ones((self.slider.value(), self.slider.value()), np.uint8)
self.processedImage = cv2.morphologyEx(self.processedImage, cv2.MORPH_CLOSE, kernel)
self.displayImage(2)
def morphGradient(self):
self.morphTransformHelper('morphGradient')
kernel = np.ones((self.slider.value(), self.slider.value()), np.uint8)
self.processedImage = cv2.morphologyEx(self.processedImage, cv2.MORPH_GRADIENT, kernel)
self.displayImage(2)
def topHat(self):
self.morphTransformHelper('topHat')
kernel = np.ones((self.slider.value(), self.slider.value()), np.uint8)
self.processedImage = cv2.morphologyEx(self.processedImage, cv2.MORPH_TOPHAT, kernel)
self.displayImage(2)
def blackHat(self):
self.morphTransformHelper('blackHat')
kernel = np.ones((self.slider.value(), self.slider.value()), np.uint8)
self.processedImage = cv2.morphologyEx(self.processedImage, cv2.MORPH_BLACKHAT, kernel)
self.displayImage(2)
functions = (dilate , erode , opening , closing , morphGradient , topHat , blackHat )