码迷,mamicode.com
首页 > 其他好文 > 详细

显著性检测(saliency detection)评价指标之KL散度距离Matlab代码实现

时间:2018-04-01 16:06:20      阅读:712      评论:0      收藏:0      [点我收藏+]

标签:nal   tin   val   一个   gen   ==   pre   blog   ase   

步骤1:先定义KLdiv函数:

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

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

% make sure map1 and map2 sum to 1
if any(map1(:))
    map1 = map1/sum(map1(:));
end

if any(map2(:))
    map2 = map2/sum(map2(:));
end

% compute KL-divergence
score = sum(sum(map2 .* log(eps + map2./(map1+eps))));

  步骤2:再写一个主函数调用它:

clear;
clc;
smap_path=‘E:\Dataset180303\final_data\smap_Result1\‘;
gmap_path=‘E:\Dataset180303\final_data\image_resize_gt\‘;
smap_file=dir(smap_path);

for j=3:length(smap_file)
    disp(j-2);
    gmap_name=strcat(gmap_path,num2str(j-2), ‘.jpg‘);
%     gmap_name=strcat(gmap_path,smap_file(j).name);
    smap_name=strcat(smap_path,num2str(j-2+ 0 ), ‘.jpg‘);
%     smap_name=strcat(smap_path,num2str(j-2+ 0 ), ‘_SaliencyMap‘, ‘.jpg‘);
    gmap=imresize(imread(gmap_name), [224, 224], ‘bicubic‘);
    smap=imresize(imread(smap_name), [224, 224], ‘bicubic‘);
    sal_map=mat2gray(smap);
    if gmap==0
        continue;
    end
    
    if size(gmap,3)==3
        gt_final_map=rgb2gray(gmap);
    else
        gt_final_map = gmap;
    end
    sal_map=imresize(sal_map,0.5);
    gt_final_map=imresize(gt_final_map,0.5);
    
    threshold_value = graythresh(gt_final_map);
    gt_final_map_bin = im2bw(gt_final_map, threshold_value);
    c = KLdiv(sal_map, gt_final_map);
    idx=find(isnan(c));
    c(idx)=0.5;
    c = abs(c);
    a(j-2,1)=mean(c);
end
% b(i-2,1)=mean(a);
% clear a;
% end
KLdiv = mean(a);

  

显著性检测(saliency detection)评价指标之KL散度距离Matlab代码实现

标签:nal   tin   val   一个   gen   ==   pre   blog   ase   

原文地址:https://www.cnblogs.com/Qsir/p/8686784.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!