1. 程式人生 > >顯著性檢測(saliency detection)評價指標之KL散度距離Matlab代碼實現

顯著性檢測(saliency detection)評價指標之KL散度距離Matlab代碼實現

mean enc gray SM tla function cor 代碼 ati

步驟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代碼實現