def calc_detection_rate(prediction,label):
'''
Calculate the detection True Positives, False Negatives and False Positives.
TP occurs whenever the prediction region intersects the ground truth region.
FP occurs
'''
label_temp=np.copy(label)
TP=FN=FP=0.0
# pattern for ndimage neighbouring pixels
s = [[1,1,1],
[1,1,1],
[1,1,1]]
labeled_prediction, num_features_prediction = ndimage.label(prediction, structure=s)
labeled_label, num_features_label = ndimage.label(label_temp, structure=s)
for i in range(1,num_features_prediction+1):
intersection=np.sum(labeled_prediction[label==1]==i)
if intersection>0:
TP+=1
else:
FP+=1
for i in range(1,num_features_label+1):
intersection=np.sum(labeled_label[prediction==1]==i)
if intersection==0:
FN=+1
return TP,FN,FP
评论列表
文章目录