首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何找到分割图像的精确性和回忆性?

如何找到分割图像的精确性和回忆性?
EN

Stack Overflow用户
提问于 2017-04-30 17:49:33
回答 1查看 1.7K关注 0票数 0

我试过这个代码

代码语言:javascript
运行
AI代码解释
复制
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。这是怎么回事?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-01 00:32:08

附加函数compareBinaryImages期望二进制输入,即只包含0和1's的输入图像。将此函数应用于二进制图像将得到几个数字输出,而非Nan:

代码语言:javascript
运行
AI代码解释
复制
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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43713245

复制
相关文章

相似问题

领券
社区富文本编辑器全新改版!诚邀体验~
全新交互,全新视觉,新增快捷键、悬浮工具栏、高亮块等功能并同时优化现有功能,全面提升创作效率和体验
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文