Matlab 显著性检测模型评价算法之KL距离

 KL距离是用来计算两个概率分布函数的差异大小:

h是ground thruth map,p是saliency map,当h和p完全相等时,KL值为0

现在一般用对称形式,即h和p换个位置,求个KL,两个KL求平均值。下面就是对称形式:关键代码:

function score = KLdiv(saliencyMap, fixationMap)
% saliencyMap is the saliency map
% fixationMap is the human fixation map, 即ground truth

map1 = im2double(imresize(saliencyMap, size(fixationMap)));
map2 = im2double(fixationMap);

% make sure map1 and map2 sum to 1,使map1上所有像素值和为1,map2一样
if any(map1(:))                    % 遍历所有像素
    map1 = map1/sum(map1(:));
end
map1(map1==0)=1e-50;               % 使map1所有像素非零

if any(map2(:))
    map2 = map2/sum(map2(:));
end
map2(map2==0)=1e-50;

% compute KL-divergence
score1 = sum(sum(map2 .* log(eps + map2./(map1+eps)))); % 相对熵
score2 = sum(sum(map1 .* log(eps + map1./(map2+eps))));
score = (score1+score2)/2;
gmap = imread(gt_full_path);
smap = imread(smap_full_path);

score = KLdiv(smap, gmap);

% created: Zoya Bylinskii, Aug 2014
 

没有更多推荐了,返回首页