-
Notifications
You must be signed in to change notification settings - Fork 5
/
preprocessindoor67.m
executable file
·67 lines (66 loc) · 2.04 KB
/
preprocessindoor67.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
% Author: Carl Doersch (cdoersch at cs dot cmu dot edu)
%
% Generate an imgs structure and save it to gbz.datasetname.
% It reads all directories contained in gbz.cutoutdir and
% collects all of the images.
function preprocessindoor67(cutoutdir,datasetfiles)
for(imset=1:2)
imdirs=dir(cutoutdir);
[~,inds]=sort({imdirs.name})
imdirs=imdirs(inds);
imgs=[];
imdata=[];
smdata=[];
if(imset==1)
mitimgs=textread('TrainImages.txt','%s','delimiter','\n');
else
mitimgs=textread('TestImages.txt','%s','delimiter','\n');
end
for(fn=1:numel(imdirs))
if(strcmp(imdirs(fn).name,'.')||strcmp(imdirs(fn).name,'..'))
continue;
end
imdirs(fn).name
imgs1=cleandir([cutoutdir '/' imdirs(fn).name]);
[~,inds]=sort({imgs1.name});
imgs1=imgs1(inds);
rand('seed',fn);
s=randperm(numel(imgs1));
imgs2={};
for(m=1:numel(imgs1))
if(~ismember(lower([imdirs(fn).name filesep imgs1(m).name]),lower(mitimgs)))
continue;
end
[~,pos]=ismember(lower([imdirs(fn).name filesep imgs1(m).name]),lower(mitimgs));
mitimgs(pos)=[];
if(dshassuffix(imgs1(m).name,'_gif.jpg'))
fnm=[cutoutdir '/' imdirs(fn).name filesep imgs1(m).name];
[im,map]=imread(fnm);
if(size(map,2)>0)
for(i=1:size(map,2))
channel=map(:,i);
data{i}=channel(im+1);
end
im=cat(3,data{:});
end
clear data
fnm(end-6:end)='jpg.jpg';
imgs1(m).name(end-6:end)='jpg.jpg';
imwrite(im,fnm,'Quality',85);
imgs1(m)=dir(fnm);
end
imgs2{end+1}.fullname=[imdirs(fn).name filesep imgs1(m).name];
imtmp=imread([cutoutdir imgs2{end}.fullname]);
sz=size(imtmp);
imgs2{end}.imsize=sz(1:2);
imgs2{end}.label=imdirs(fn).name;
end
imgs=[imgs;cell2mat(imgs2')];
%imdata=[imdata; imdata1];
%smdata=[smdata;smdata1];
end
imgs=str2effstr(imgs);
labelnames=sort(unique(imgs.label));
[~,imgs.label]=ismember(imgs.label,labelnames);
save(datasetfiles{imset},'imgs','labelnames');
end