-
Notifications
You must be signed in to change notification settings - Fork 4
/
CallIOU_fix.m
58 lines (46 loc) · 1.14 KB
/
CallIOU_fix.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function iou = CallIOU_fix(sal_dir, gt_dir, count_bg)
files = dir([gt_dir '/*.png']);
if isempty(files)
iou = NaN;
return;
end
files = dir([sal_dir '/*.png']);
if isempty(files)
iou = NaN;
return;
end
result = [];
for i=1:length(files)
try
name = files(i).name;
gt = imread([gt_dir '/' name(1:end-4) '.png']);
gt = gt(:,:,1);
gt(gt>0) = 1;
gt = double(gt);
sal = imread([sal_dir '/' name(1:end-4) '.png']);
sal = sal(:,:,1);
sal = (im2double(sal));
threshold = 0.5;
%if(sum(gt(:)) == 0 && (sum(sum(sal >= threshold)) == 0 || sum(sal(:)) == 0))
if(sum(sal(:)) == 0)
else
sal(sal<threshold) = 0;
sal(sal>=threshold) = 1;
end
if(sum(gt(:)) == 0)
sal(1,1) = 1;
gt(1,1) = 1;
%if(count_bg)
sal = 1-sal;
gt = 1 - gt;
%end
end
iou = IOU(sal, gt);
result = [result; iou];
catch
disp(name);
end
end
%iou = nanmean(result(:));
iou = result(:);;
end