We have tried calculating the artery to venal ratio,but on calculation the ratio is remaining unchanged for different images.we are unable to debug it.
# detecting artery and vein
mask2 = cv2.imread('D:/Desktop/MINI PROJECT/Hypertensive-Retinopathy-Detection-master/image01.tiff')
imgseg = cv2.imread('D:/Desktop/MINI PROJECT/Hypertensive-Retinopathy-Detection-master/inverted01.tiff')
_,mask2,_= cv2.split(mask2)
cv2.imshow('segmented image',mask2)
print(mask.shape,mask2.shape)
count = 0
intensity = 0
for x in range(mask.shape[0]):
for y in range(mask.shape[1]):
if mask[x][y] and mask2[x][y]:
intensity = intensity + imgseg[x][y][1]
count = count + 1
print('intensity sum {}'.format(intensity))
intensitymean = int(intensity/count)
print('intensity mean {} and count {}'.format(intensitymean,count))
artery = mask.copy()
vein = mask.copy()
cv2.imshow('artery before',artery)
cv2.imshow('veins before',vein)
for x in range(mask.shape[0]):
for y in range(mask.shape[1]):
if mask[x][y] and mask2[x][y]:
if imgseg[x][y][1] >= intensitymean-15:
artery[x][y] = 0
else:
vein[x][y] = 0
cv2.imshow('artery',artery)
cv2.imshow('veins',vein)
cv2.imshow('whats this',vein-artery)
# arteriovenus ratio
# invert
artery = 255 - artery
vein = 255 - vein
cv2.imshow('inverted artery', artery)
cv2.imshow('inverted vein', vein)
#cv2.imwrite('F:/DESKTOP/Downloads/Hypertensive-Retinopathy-Detection-master/artery.tiff',artery)
#cv2.imwrite('F:/DESKTOP/Downloads/Hypertensive-Retinopathy-Detection-master/vein.tiff',vein)
# distance transform
print(artery.dtype)
arteryDist = cv2.distanceTransform(artery,cv2.DIST_L1, cv2.DIST_MASK_PRECISE)
veinDist = cv2.distanceTransform(vein,cv2.DIST_L1, cv2.DIST_MASK_PRECISE)
cv2.imshow('distance transformed artery', arteryDist)
cv2.imshow('distance transformed vein', veinDist)
#cv2.imwrite('F:/DESKTOP/Downloads/Hypertensive-Retinopathy-Detection-master/veinDist.png', veinDist)
# thinning
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
size = np.size(arteryDist)
arteryskel = np.zeros(arteryDist.shape,np.uint8)
done = False
while( not done):
eroded = cv2.erode(arteryDist,kernel)
temp = cv2.dilate(eroded,kernel)
temp = cv2.subtract(arteryDist,temp)
arteryskel = temp.copy()
arteryDist = eroded.copy()
if cv2.countNonZero(arteryDist) == 0:
done = True
print(cv2.countNonZero(arteryskel))
cv2.imshow('thinned image artery',arteryskel)
veinskel = np.zeros(veinDist.shape,np.uint8)
done = False
while( not done):
eroded = cv2.erode(veinDist,kernel)
temp = cv2.dilate(eroded,kernel)
temp = cv2.subtract(veinDist,temp)
veinskel = temp.copy()
veinDist = eroded.copy()
if cv2.countNonZero(arteryDist) == 0:
done = True
print(cv2.countNonZero(veinskel))
cv2.imshow('thinned image vein',veinskel)
venuole = []
arteriole = []
for x in range(veinskel.shape[0]):
for y in range(veinskel.shape[1]):
if veinskel[x][y] > 0:
venuole.append(veinskel[x][y])
if arteryskel[x][y] > 0:
arteriole.append(arteryskel[x][y])
venuole = sorted(venuole)
arteriole = sorted(arteriole)
lenven = len(venuole)
print('length of lenven {} {} {}'.format(lenven,lenven//2,lenven//2-1))
lenart = len(arteriole)
print('length of lenart {} {} {}'.format(lenart,lenart//2,lenart//2-1))
if lenven%2 == 1:
Wa = venuole[lenven//2]
if lenven//2 == 0:
Wb = venuole[0]
else:
Wb = venuole[lenven//2 - 1]
else:
Wa = (venuole[lenven//2 - 1] + venuole[lenven//2])// 2
Wb = venuole[lenven//2 - 1]
print("Wa,Wb",Wa,Wb)
CRVE = sqrt(0.72*(Wa**2) + 0.91*(Wb**2) + 450.02)
if lenart%2 == 1:
Wa = arteriole[lenart//2]
if lenart//2 == 0:
Wb = arteriole[0]
else:
Wb = arteriole[lenart//2 - 1]
else:
Wa = (arteriole[lenart//2 - 1] + arteriole[lenart//2])// 2
Wb = arteriole[lenart//2 - 1]
print(arteriole)
print("wa,wb",Wa,Wb)
CRAE = sqrt(0.87*(Wa**2) + 1.01*(Wb**2) - 0.22*(Wa*Wb) - 0.73)
artervenratio = CRAE/CRVE
print('arteriovenous ratio {}'.format(artervenratio))
cv2.waitKey(0)
We are not getting correct value of wa and wb hence the calculation of AVR is also coming wrong.
Could you please help us debug the code.