程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python measurement index template

編輯:Python
import cv2
import glob
import os
import numpy as np
from medpy import metric
def calculate_metric_percase(pred, gt):
# dice = metric.binary.dc(pred, gt)
# jc = metric.binary.jc(pred, gt)
hd = metric.binary.hd95(pred, gt)
asd = metric.binary.asd(pred, gt)
return hd, asd
dice_mean = 0
hd_mean = 0
asd_mean = 0
hd = list()
asd =list()
predlist=glob.glob(os.path.join('./Dataset/data2/predict', "*"))# Predicted folder path
gtlist=glob.glob(os.path.join('./Dataset/data2/val/M', "*"))# Truth folder path
for i in range(len(predlist)):
print(i, os.path.basename(predlist[i]))
img_ground = cv2.imread(predlist[i])
img_predict = cv2.imread(gtlist[i])
x = 0
y = 0
for w in range(256):
for h in range(256):
x += img_ground.item(w, h, 1)/255
y += img_predict.item(w, h, 1)/255
if x + y == 0 or x == 0 or y == 0:
current_hd=0
current_asd=0
else:
current_hd, current_asd = calculate_metric_percase(img_predict, img_ground)
print('hd', current_hd, 'asd', current_asd)
hd_mean += current_hd
hd.append((current_hd))
asd_mean += current_asd
asd.append((current_asd))
hd_mean /=len(predlist)
asd_mean /=len(predlist)
print('Dice',dice_mean)
print('hd',hd_mean,'asd',asd_mean)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved