图像分割评价标准 代码 (Image segmentation evaluation metrics code)

% % test all segmentation metric functions
% SEG = imread('0.png');
% GT = imread('1.png');

function [dice,hd,jaccard,apd,confm_index,precision,recall]=access_img(SEG,GT)
% binarize
SEG = im2bw(SEG, 0.1);
GT = im2bw(GT, 0.1);

dice = Dice_Ratio(SEG, GT);
hd = Hausdorff_Dist(SEG, GT);
jaccard = Jaccard_Index(SEG, GT);
apd = Avg_PerpenDist(SEG, GT);
confm_index = ConformityCoefficient(SEG, GT);
precision = Precision(SEG, GT);
recall = Recall(SEG, GT);
end

% Dice_Ratio:
function dr = Dice_Ratio(SEG, GT)
    % SEG, GT are the binary segmentation and ground truth areas, respectively.
    % dice ratio
    dr = 2*double(sum(uint8(SEG(:) & GT(:)))) / double(sum(uint8(SEG(:))) + sum(uint8(GT(:))));
end

% Hausdorff_Dist (得到hd 之后,还需要乘以像素的物理距离,才是真正的 Hausdorff 距离)(update: 对于三维体数据中该距离的计算,ITK方面给出的计算流程是:先将体数据匹配到同一物理空间,然后进行计算,这就要求两个体数据必须具备相同的物理参数。所以本代码不适用于三维体数据的计算。):
function hd = Hausdorff_Dist(SEG, GT)
    % SEG, GT are the binary segmentation and ground truth areas, respectively.
    % erode element
    s = cat(3, [0 0 0 ; 0 1 0 ; 0 0 0], [0 1 0 ; 1 1 1 ; 0 1 0], [0 0 0 ; 0 1 0 ; 0 0 0]);
    % generate boundary
    Boundary_SEG = logical(SEG) & ~imerode(logical(SEG), s);
    Boundary_GT = logical(GT) & ~imerode(logical(GT), s);
    % distance to nearest boundary point
    Dist_SEG = bwdist(Boundary_SEG, 'euclidean');
    Dist_GT = bwdist(Boundary_GT, 'euclidean');
    % distance to another boundary
    min_S2G = sort(Dist_GT( Boundary_SEG(:) ), 'ascend');
    min_G2S = sort(Dist_SEG( Boundary_GT(:) ), 'ascend');
    % hausdorff distance
    hd = max(min_S2G(end), min_G2S(end));
end

% Jaccard_Index:
function jaccard = Jaccard_Index(SEG, GT)
    % SEG, GT are the binary segmentation and ground truth areas, respectively.
    % jaccard index
    jaccard = double(sum(uint8(SEG(:) & GT(:)))) / double(sum(uint8(SEG(:) | GT(:))));
end

% Avg_PerpenDist (得到 apd 之后,还需要乘以像素的物理距离,才是真正的 apd 值):
function apd = Avg_PerpenDist(SEG, GT)
    % SEG, GT are the binary segmentation and ground truth areas, respectively.
    % erode element
    s = cat(3, [0 0 0 ; 0 1 0 ; 0 0 0], [0 1 0 ; 1 1 1 ; 0 1 0], [0 0 0 ; 0 1 0 ; 0 0 0]);
    % generate boundary
    Boundary_SEG = logical(SEG) & ~imerode(logical(SEG), s);
    Boundary_GT = logical(GT) & ~imerode(logical(GT), s);
    % distance to nearest boundary point
    Dist_GT = bwdist(Boundary_GT, 'euclidean');
    % distance to another boundary
    min_S2G = Dist_GT( Boundary_SEG(:) );
    % average perpendicular distance from SEG to GT
    apd = sum(min_S2G(:)) / length(min_S2G(:));
end

% ConformityCoefficient:
function confm_index = ConformityCoefficient(SEG, GT)
    % SEG, GT are the binary segmentation and ground truth areas, respectively.
    % dice ratio
    dr = 2*double(sum(uint8(SEG(:) & GT(:)))) / double(sum(uint8(SEG(:))) + sum(uint8(GT(:))));
    % conformity coefficient
    confm_index = (3*dr - 2) / dr;
end

% Precision:
function precision = Precision(SEG, GT)
    % SEG, GT are the binary segmentation and ground truth areas, respectively.
    % precision
    precision = double(sum(uint8(SEG(:) & GT(:)))) / double(sum(uint8(SEG(:))));
end

% Recall:
function recall = Recall(SEG, GT)
    % SEG, GT are the binary segmentation and ground truth areas, respectively.
    % recall
    recall = double(sum(uint8(SEG(:) & GT(:)))) / double(sum(uint8(GT(:))));
end

 

转载

% --------------------- 
% 作者:Life_XY 
% 来源:CSDN 
% 原文:https://blog.csdn.net/yangyangyang20092010/article/details/51637073 
% 版权声明:本文为博主原创文章,转载请附上博文链接!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值