-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main_SDL.m
executable file
·86 lines (70 loc) · 3.44 KB
/
Main_SDL.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
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
%%%%%%%%%%%%%%%%%%% File for creating directories, superpixel-gabor features, image
%%%%%%%%%%%%%%%%%%% saliency and storing them in a file at a given location
clc
clear all
add_utilities;
run(strcat(cd,'/Utilities/VLFEATROOT/toolbox/vl_setup.m'));
datapath = cd;
datafolder = '/Bisque' ;% path where images are saved
resultFolder = '/results';
subfldrsup = '/suppixmap'; % superpixels, saliency, features
%subfldrblck = '/blocksmap'; % superpixels, saliency, features
subfldrdictSal = '/dictSal'; % dictionary SIFT with saliency, saliency update
subfldrdictFull = '/dictFull'; % dictionary full no saliency and saliency thresh
%subfldrdictBlk = '/dictSiftBlk'; % dictionary with blocks full and saliency wt
% %subfldrdictG = '/dictionaryGb'; % superpixels, saliency, features
imtype = 'jpg';
numsuppixels = 500;
%
%
mkdir(strcat(datapath,resultFolder,datafolder))
mkdir(strcat(datapath,resultFolder,datafolder,subfldrsup,num2str(numsuppixels)))
%mkdir(strcat(datapath,resultFolder,datafolder,subfldrblck,num2str(numsuppixels)))
mkdir(strcat(datapath,resultFolder,datafolder,subfldrdictSal,num2str(numsuppixels)))
mkdir(strcat(datapath,resultFolder,datafolder,subfldrdictFull,num2str(numsuppixels)))
%mkdir(strcat(datapath,resultFolder,datafolder,subfldrdictBlk,num2str(numsuppixels)))
%% uncomment if you need to read images from a folder
%[fileNames,subfolders,filenum] = readimgfilenames(datapath,datafolder,imtype);
%numimg = 10; % numofimages for training
%[trainfnameByclass,trainFnames,trainFilesgray,trainfilecolor] = readimgfiles(numimg,subfolders,fileNames);
%save(strcat(cd,resultFolder,datafolder,'/','filenames.mat'),'fileNames','filenum');
%% define paths
dpath = strcat(cd,resultFolder,datafolder);
Supfeapath = strcat(dpath,subfldrsup,num2str(numsuppixels));
%Blckfeapath= strcat(dpath,subfldrblck,num2str(numsuppixels));
dpathSal = strcat(dpath,subfldrdictSal,num2str(numsuppixels));
dpathFull = strcat(dpath,subfldrdictFull,num2str(numsuppixels));
%dpathBlck = strcat(dpath,subfldrdictBlk,num2str(numsuppixels));
load('allimgfilesBisque.mat')
disp('load done \\n');
%%
numOfzero = 5;
numzero = strcat('%0',num2str(numOfzero),'d');
numsup = numsuppixels;
block_size = 8;
param.poscont = 0;
param.disp = 0;
params_gabor = struct('stage',4, 'orientation',8,...
'Ul',0.05, 'Uh',0.4, 'flag',0);
%% %%%%%%%%%%%%%%% Can run this in parallel for each image for feature %%%%%%%%%%%%%%%
for imgnum=1:1:length(trainfilecolor)
r{imgnum} = parallelGabor(trainfilecolor,imgnum,block_size,Supfeapath,numzero,param,params_gabor);
end
%% %%%%%%%%%%%%%%%% Running for learning dictionary %%%%%%%%%%%%%%%%%%%%%%%%
% Dictionary learning paramters
err1 = 0.0001;
paramsalnonthresh = struct('K',round(0.2*numsup),'L',round(0.04*numsup),'numIteration',50,...
'errorFlag',1,'errorGoal',err1,'preserveDCAtom',0,'displayProgress',0,'sigma',1*regionSize);
suppixfile = dir(strcat(Supfeapath)); % path to read the superpixels and saliency
k=1;
for i=1:1:length(suppixfile)
if (suppixfile(i).bytes~=0)
datafile{k} = strcat(Supfeapath,'/',suppixfile(i).name);
k=k+1;
end
end
disp('read file done \n')
%%%% the dictionary for each image can be computed parallelly %%%%%%
parfor imgnum=1:1:length(datafile)
varpar{imgnum} = computeparallelGdict(datafile,imgnum,dpathSal,paramsalnonthresh,numzero);
end