【问题标题】:How to find precision and recall of segmented image?如何找到分割图像的精度和召回率?
【发布时间】:2017-09-28 12:32:37
【问题描述】:

我试过这个code:

function [Fvalue,precision,recall,accuracy,JaccardIndex,TP,FP,TN,FN,FPrate,TPrate,MCC] = compareBinaryImages( reference, toTest )
%COMPAREBINARYIMAGES Compute various similarity metrics between two binary images
%   reference = grouth truth binary image
%   toTest = binary image to be compared to the reference image

if(ndims(reference)~=2 && ndims(toTest)~=2) 
    error('Inputs must be two 2-dimensional matrices'); 
end; 

%  TP = numel(find(reference==1 & toTest==1)==1); % True positive
%  FP = numel(find(reference==0 & toTest==1)==1); % False positive
%  TN = numel(find(reference==0 & toTest==0)==1); % True negative
%  FN = numel(find(reference==1 & toTest==0)==1); % False negative


 TP = nnz(reference==1 & toTest==1); % True positive
 FP = nnz(reference==0 & toTest==1); % False positive
 TN = nnz(reference==0 & toTest==0); % True negative
 FN = nnz(reference==1 & toTest==0); % False negative

P = TP + FN; % Total positive for the true class (= reference)
N = FP + TN; % TOtal negative for the true class (= reference)

FPrate = FP/N; % False positive rate
TPrate = TP/P; % True positive rate

precision = TP/(TP+FP);
recall = TP/P;
accuracy = (TP+TN)/(P+N);

MCC = (TP*TN-FP*FN)/sqrt((TP+FP)*(TP+FN)*(TN+FP)*(TN+FN));
2/((1/precision)+(1/recall));

% Alternative form for Fvalue
2*(precision*recall/(precision+recall));

% Avoid getting a division by 0 if only negatives and perfect detection
if(TN==numel(reference))
    'gaga'
    Fvalue = 1;
    warning('FValue was set to 1 as all pixels were true negatives');
else
    Fvalue=2*TP/(FP+TP+P);
end

2*TP/((FP+TP)+(TP+FN));

JaccardIndex = TP / (FP+TP+FN);

end

我的测试图片是

我的参考图片是

但我得到的结果是 NaN。这有什么问题?

【问题讨论】:

  • NaN 是什么结果?链接中的函数有多个输出。你试过调试代码吗?
  • yes.i 使用 rgb2gray(reference) 和 rgb2gray(toTest) 然后 compareBinaryImages(reference, toTest ) ans = NaN

标签: matlab image-segmentation


【解决方案1】:

附加函数 compareBinaryImages 需要 二进制 输入,即仅包含 0 和 1 的输入图像。对图像进行二值化并将此函数应用于二值图像会产生几个数字输出,其中非 Nan:

testingImg = imread('testing.png');
referenceImg = imread('reference.png');
% grayscale
testingGray = rgb2gray(testingImg);
referenceGray = rgb2gray(referenceImg);
% binarize
testingBw = testingGray == 255;
referenceBw = referenceGray == 255;
% compare *binary* images
[Fvalue,precision,recall,accuracy,JaccardIndex,TP,FP,TN,FN,FPrate,TPrate,MCC] = ...
    compareBinaryImages(referenceBw, testingBw);

【讨论】:

  • 但为什么要大值? TP = 7117 FP = 1990 TN = 368716 FN = 2866
  • 你应该仔细阅读这些值的定义,你就会明白。例如,TP(真阳性)是 像素数,在测试图像和参考图像中均为 1。
猜你喜欢
  • 2011-11-01
  • 2023-04-07
  • 1970-01-01
  • 2014-11-20
  • 2016-06-19
  • 1970-01-01
  • 2012-11-26
  • 2014-02-20
  • 1970-01-01
相关资源
最近更新 更多