-
Notifications
You must be signed in to change notification settings - Fork 17
/
eDNsaliency
executable file
·124 lines (103 loc) · 3.84 KB
/
eDNsaliency
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
import optparse
import numpy as np
from scipy import misc
from scipy import ndimage
import logging
import pickle
from liblinearutil import load_model
from eDNSalModel import EDNSaliencyModel
from evaluation import evaluate_sal_map
from imageOps import hist_equalize_maps
def eDNsaliency(imgPath, outPath, opts):
# read image
img = misc.imread(imgPath)
# read eDN model(s)
descFile = open(opts.descPath, 'r')
desc = pickle.load(descFile)
descFile.close()
nFeatures = np.sum([d['desc'][-1][0][1]['initialize']['n_filters']
for d in desc if d != None])
# load SVM model and whitening parameters
svm = load_model(opts.svmPath)
f = open(opts.whitePath, 'r')
whiteParams = np.asarray([map(float, line.split(' ')) for line in f]).T
f.close()
# assemble svm model
svmModel = {}
svmModel['svm'] = svm
svmModel['whitenParams'] = whiteParams
biasToCntr = (svm.get_nr_feature()-nFeatures) == 1
# compute saliency map
model = EDNSaliencyModel(desc, svmModel, biasToCntr)
salMap = model.saliency(img, normalize=False)
salMap = salMap.astype('f')
if not opts.noBlur:
salMap = ndimage.gaussian_filter(salMap, sigma=30)
# read fixation map / empirical saliency map
if opts.fixMap:
fixMap = misc.imread(opts.fixMap)
# compute AUC
if opts.auc:
auc = evaluate_sal_map(salMap, fixMap)
logging.info("AUC = %f" % auc)
# for fair visual comparison, perform histogram equalization with
# empirical saliency map
if opts.histeq:
salMap = hist_equalize_maps(fixMap, salMap)
# normalize and save the saliency map to disk
normSalMap = (255.0 / (salMap.max()-salMap.min()) *
(salMap-salMap.min())).astype(np.uint8)
misc.imsave(outPath, normSalMap)
def get_optparser():
usage = "usage: %prog [--opts] <image_path> <output_saliency_map>"
parser = optparse.OptionParser(usage=usage)
parser.add_option("--descs",
dest="descPath",
default='slmBestDescrCombi.pkl', # in current directory
help="path to SLM model(s) (default: ./slmBestDescrCombi.pkl)")
parser.add_option("--svm",
dest="svmPath",
default='svm-slm-cntr', # in current directory
help="path to SVM file (default: ./svm-slm-cntr)")
parser.add_option("--white",
dest="whitePath",
default='whiten-slm-cntr', # in current directory
help="path to whitening parameters (default: ./whiten-slm-cntr)")
parser.add_option("--fixMap",
dest="fixMap",
default=None,
help="fixation map / empirical saliency map, if available")
parser.add_option("--histeq",
action="store_true",
dest="histeq",
default=False,
help="histogram equalization with given empirical saliency map "
"(default: False); requires empirical saliency map")
parser.add_option("--auc",
action="store_true",
dest="auc",
default=False,
help="compute AUC for given fixation map (default: False); "
"requires fixation map")
parser.add_option("--no-blur",
action="store_true",
dest="noBlur",
default=False,
help="Do not blur the final saliency map (default: False)")
return parser
def main():
logging.basicConfig(level=logging.INFO, format='%(message)s')
parser = get_optparser()
opts, args = parser.parse_args()
if len(args)<1 or len(args)>2 or (opts.histeq and not opts.fixMap):
parser.print_help()
else:
imgPath = args[0]
if len(args) == 2:
outPath = args[1]
else:
outPath = "salMap.jpg"
eDNsaliency(imgPath, outPath, opts)
if __name__ == "__main__":
main()