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', "*"))#预测文件夹路径
gtlist=glob.glob(os.path.join('./Dataset/data2/val/M', "*"))#真值文件夹路径


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)

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值