MAE
定义
Mean Absolute Error(平均绝对误差), 观测值与真实值的误差绝对值的平均值。
计算方式
M A E = 1 H × W ∑ x = 1 H ∑ y = 1 W ∣ P ( x , y ) − G ( x , y ) ∣ MAE=\frac{1}{H \times W} \sum_{x=1}^{H} \sum_{y=1}^{W}|P(x, y)-G(x, y)| MAE=H×W1∑x=1H∑y=1W∣P(x,y)−G(x,y)∣
function mae = MAE(smap, gtImg)
% Code Author: Wangjiang Zhu
% Email: wangjiang88119@gmail.com
% Date: 3/24/2014
if size(smap, 1) ~= size(gtImg, 1) || size(smap, 2) ~= size(gtImg, 2)
error('Saliency map and gt Image have different sizes!\n');
end
if ~islogical(gtImg)
gtImg = gtImg(:,:,1) > 128;
end
fgPixels = smap(gtImg);
fgErrSum = length(fgPixels) - sum(fgPixels);
bgErrSum = sum(smap(~gtImg));
mae = (fgErrSum + bgErrSum) / numel(gtImg);
Fmeasure
定义
用来平衡准确率和召回率的评估值
计算方式
F β = ( 1 + β 2 ) × Precision × Recall β 2 × Precision + Recall F_{\beta}=\frac{\left(1+\beta^{2}\right) \times \text { Precision } \times \text { Recall }}{\beta^{2} \times \text { Precision }+\text { Recall }} Fβ=β2× Precision + Recall (1+β2)× Precision × Recall
其中 β 2 \beta^2 β2一般取0.3
P = T P T P + F P P=\frac{TP}{TP+FP} P=TP+FPTP
R = T P T P + F N R=\frac{TP}{TP+FN} R=TP+FNTP
这幅图形象地说明了精确率和召回率的计算关系。
这里贴出代码
function [PreFtem, RecallFtem, FmeasureF] = Fmeasure(sMap, gtMap, gtsize)
sumLabel = 2* mean(sMap(:));
if (sumLabel > 1)
sumLabel = 1;
end
Label3 = zeros( gtsize );
Label3(sMap>=sumLabel ) = 1;
NumRec = length( find( Label3==1 ) );
LabelAnd = Label3 & gtMap; %TP
NumAnd = length( find ( LabelAnd==1 ) );
num_obj = sum(sum(gtMap));
if NumAnd == 0
PreFtem = 0;
RecallFtem = 0;
FmeasureF = 0;
else
PreFtem = NumAnd/NumRec;
RecallFtem = NumAnd/num_obj;
FmeasureF = ((1.3*PreFtem*RecallFtem)/(0.3*PreFtem+RecallFtem));
end
Smeasure
定义
计算前景像素与真值的相似度
计算方式
S m = α ∗ S o + ( 1 − α ) ∗ S r S_{m}=\alpha * S_{o}+(1-\alpha) * S_{r} Sm=α∗So+(1−α)∗Sr
S o = 2 ∗ E ( p r e ) E ( p r e ) 2 + 1 + σ + e S_{o}=\frac{2*E(pre)}{E(pre)^2+1+\sigma+e} So=E(pre)2+1+σ+e2∗E(pre)
S r S_{r} Sr表示按重心位置,然后切割成四个区域,对四个区域按像素占整张图的区域面积作为权重,计算四个区域SSIM的加权平均。其实就是对滑窗法做了改进
function Q = Smeasure(prediction,GT)
% Smeasure computes the similarity between the foreground map and
% ground truth(as proposed in "Structure-measure: A new way to evaluate
% foreground maps" [Deng-Ping Fan et. al - ICCV 2017])
% Usage:
% Q = Smeasure(prediction,GT)
% Input:
% prediction - Binary/Non binary foreground map with values in the range
% [0 1]. Type: double.
% GT - Binary ground truth. Type: logical.
% Output:
% Q - The computed similarity score
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Check input
if (~isa(prediction,'double'))
error('The prediction should be double type...');
end
if ((max(prediction(:))>1) || min(prediction(:))<0)
error('The prediction should be in the range of [0 1]...');
end
if (~islogical(GT))
error('GT should be logical type...');
end
y = mean2(GT);
if (y==0)% if the GT is completely black
x = mean2(prediction);
Q = 1.0 - x; %only calculate the area of intersection
elseif(y==1)%if the GT is completely white
x = mean2(prediction);
Q = x; %only calcualte the area of intersection
else
alpha = 0.5;
Q = alpha*S_object(prediction,GT)+(1-alpha)*S_region(prediction,GT);
end
end
PR_Curve
定义
对精确率和召回率做直方图,然后对每个直方图做累加和,分别计算精确率和召回率,最终形成一组曲线。
计算方式
function [precision, recall] = CalPR(smapImg, gtImg)
% Code Author: Wangjiang Zhu
% Email: wangjiang88119@gmail.com
% Date: 3/24/2014
if ~islogical(gtImg)
gtImg = gtImg(:,:,1) > 128;
end
if any(size(smapImg) ~= size(gtImg))
error('saliency map and ground truth mask have different size');
end
gtPxlNum = sum(gtImg(:));
if 0 == gtPxlNum
error('no foreground region is labeled');
end
targetHist = histc(smapImg(gtImg), 0:255);
nontargetHist = histc(smapImg(~gtImg), 0:255);
targetHist = flipud(targetHist);
nontargetHist = flipud(nontargetHist);
targetHist = cumsum( targetHist );
nontargetHist = cumsum( nontargetHist );
precision = targetHist ./ (targetHist + nontargetHist + eps);
if any(isnan(precision))
warning('there exists NAN in precision, this is because your saliency map do not range from 0 to 255\n');
end
recall = targetHist / gtPxlNum;