-
Notifications
You must be signed in to change notification settings - Fork 1
/
features.py
108 lines (90 loc) · 3.94 KB
/
features.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import numpy as np
import cv2 as cv
from skimage import morphology
class ExtractBloodVessels:
image = 0
def readImage(self, img):
self.image = np.array(img)
return self.image
def greenComp(self, image):
gcImg = self.image[:, :, 1]
self.image = gcImg
return self.image
def histEqualize(self, image):
histEqImg = cv.equalizeHist(self.image)
self.image = histEqImg
return self.image
def kirschFilter(self, image):
gray = self.image
if gray.ndim > 2:
raise Exception("illegal argument: input must be a single channel image (gray)")
kernelG1 = np.array([[5, 5, 5],
[-3, 0, -3],
[-3, -3, -3]], dtype=np.float32)
kernelG2 = np.array([[5, 5, -3],
[5, 0, -3],
[-3, -3, -3]], dtype=np.float32)
kernelG3 = np.array([[5, -3, -3],
[5, 0, -3],
[5, -3, -3]], dtype=np.float32)
kernelG4 = np.array([[-3, -3, -3],
[5, 0, -3],
[5, 5, -3]], dtype=np.float32)
kernelG5 = np.array([[-3, -3, -3],
[-3, 0, -3],
[5, 5, 5]], dtype=np.float32)
kernelG6 = np.array([[-3, -3, -3],
[-3, 0, 5],
[-3, 5, 5]], dtype=np.float32)
kernelG7 = np.array([[-3, -3, 5],
[-3, 0, 5],
[-3, -3, 5]], dtype=np.float32)
kernelG8 = np.array([[-3, 5, 5],
[-3, 0, 5],
[-3, -3, -3]], dtype=np.float32)
g1 = cv.normalize(cv.filter2D(gray, cv.CV_32F, kernelG1), None, 0, 255, cv.NORM_MINMAX, cv.CV_8UC1)
g2 = cv.normalize(cv.filter2D(gray, cv.CV_32F, kernelG2), None, 0, 255, cv.NORM_MINMAX, cv.CV_8UC1)
g3 = cv.normalize(cv.filter2D(gray, cv.CV_32F, kernelG3), None, 0, 255, cv.NORM_MINMAX, cv.CV_8UC1)
g4 = cv.normalize(cv.filter2D(gray, cv.CV_32F, kernelG4), None, 0, 255, cv.NORM_MINMAX, cv.CV_8UC1)
g5 = cv.normalize(cv.filter2D(gray, cv.CV_32F, kernelG5), None, 0, 255, cv.NORM_MINMAX, cv.CV_8UC1)
g6 = cv.normalize(cv.filter2D(gray, cv.CV_32F, kernelG6), None, 0, 255, cv.NORM_MINMAX, cv.CV_8UC1)
g7 = cv.normalize(cv.filter2D(gray, cv.CV_32F, kernelG7), None, 0, 255, cv.NORM_MINMAX, cv.CV_8UC1)
g8 = cv.normalize(cv.filter2D(gray, cv.CV_32F, kernelG8), None, 0, 255, cv.NORM_MINMAX, cv.CV_8UC1)
magn = cv.max(g1, cv.max(g2, cv.max(g3, cv.max(g4, cv.max(g5, cv.max(g6, cv.max(g7, g8)))))))
self.image = magn
return self.image
def threshold(self, image):
ret, threshImg = cv.threshold(self.image, 160, 180, cv.THRESH_BINARY_INV)
self.image = threshImg
return self.image
def clearSmallObjects(self, image):
cleanImg = morphology.remove_small_objects(self.image, min_size=130, connectivity=100)
self.image = cleanImg
return self.image
class ExtractExudates:
image = 0
def readImage(self, img):
self.image = np.array(img)
return self.image
def greenComp(self, image):
gcImg = image[:, :, 1]
image = gcImg
return image
def CLAHE(self, image):
clahe = cv.createCLAHE()
clImg = clahe.apply(image)
image = clImg
return image
def dilation(self, image):
strEl = cv.getStructuringElement(cv.MORPH_ELLIPSE, (6, 6))
dilateImg = cv.dilate(image, strEl)
image = dilateImg
return image
def threshold(self, image):
retValue, threshImg = cv.threshold(image, 220, 220, cv.THRESH_BINARY)
image = threshImg
return image
def medianFilter(self, image):
medianImg = cv.medianBlur(image, 5)
image = medianImg
return image