def batchProcess(imgPath, outPath, opts):
    # 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

    model = EDNSaliencyModel(desc, svmModel, biasToCntr)

    puts(colored.yellow("Collecting image filenames..."))
    todo_list = [ f for f in listdir(imgPath) if isfile(join(imgPath,f)) ]
    existing_list = [ f for f in listdir(outPath) if isfile(join(outPath,f)) ]
    #image_list.sort()
    puts("Done")

    for f in todo_list:
        if f not in existing_list:
            print '-------------------------------------------------------------'
            print 'processing', f
            print

            try:
                # read image
                img = misc.imread(join(imgPath,f))
                # compute saliency map
                salMap = model.saliency(img, normalize=False)
                # normalize and save the saliency map to disk
                normSalMap = (255.0 / (salMap.max()-salMap.min()) *
                         (salMap-salMap.min())).astype(np.uint8)
                misc.imsave(join(outPath,f), normSalMap)

            except Exception as e:
                puts(colored.red('ERROR: {}'.format(e)))
                puts(colored.yellow('filename: {}'.format(f)))
        else:
            print '-------------------------------------------------------------'
            puts(colored.yellow('Saliency map already exists! ({})'.format(f)))
            print
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)