-
Notifications
You must be signed in to change notification settings - Fork 4
/
microaneurysm.py
39 lines (29 loc) · 1.07 KB
/
microaneurysm.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
#optimisation required
import cv2
import numpy as np
def adjust_gamma(image, gamma=1.0):
table = np.array([((i / 255.0) ** gamma) * 255
for i in np.arange(0, 256)]).astype("uint8")
return cv2.LUT(image, table)
def extract_ma(image):
r,g,b=cv2.split(image)
comp=255-g
clahe = cv2.createCLAHE(clipLimit=5.0, tileGridSize=(8,8))
histe=clahe.apply(comp)
adjustImage = adjust_gamma(histe,gamma=3)
comp = 255-adjustImage
J = adjust_gamma(comp,gamma=4)
J = 255-J
J = adjust_gamma(J,gamma=4)
K=np.ones((11,11),np.float32)
L = cv2.filter2D(J,-1,K)
ret3,thresh2 = cv2.threshold(L,125,255,cv2.THRESH_BINARY|cv2.THRESH_OTSU)
kernel2=np.ones((9,9),np.uint8)
tophat = cv2.morphologyEx(thresh2, cv2.MORPH_TOPHAT, kernel2)
kernel3=np.ones((7,7),np.uint8)
opening = cv2.morphologyEx(tophat, cv2.MORPH_OPEN, kernel3)
return opening
if __name__ == "__main__":
fundus = cv2.imread("22.jpg")
bloodvessel = extract_ma(fundus)
cv2.imwrite("22_MA.png",bloodvessel)