-
Notifications
You must be signed in to change notification settings - Fork 4
/
shallowLoad.m
165 lines (119 loc) · 3.98 KB
/
shallowLoad.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
function [shallowObj msg]=shallowLoad(filename)
if nargin==0
[file,path] = uigetfile('*.mat','Select a shallow project',pwd);
if isequal(file,0)
disp('User selected Cancel')
msg=[];
shallowObj=[];
return;
else
disp(['User selected ', fullfile(path, file)]);
filename=fullfile(path, file);
end
end
[path file ext]=fileparts(filename);
%filename
abspath=what(path);
abspath=abspath.path;
filename=fullfile(abspath,[file ext]);
load(filename);
if ~exist('shallowObj')
disp('this is not a shallow object ! Quitting....');
msg=['Wrong file name loaded'];
shallowObj=[];
return;
end
if ~isfield(shallowObj.processing,'processor')
shallowObj.processing.processor=[];
end
path=abspath;
if isunix || ismac
shallowObj.setPath([path '/'],file); % adjust path
else
shallowObj.setPath([path '\'],file); % adjust path
end
% check if project is already open in the workspace
varlist=evalin('base','who');
for i=1:numel(varlist)
if strcmp(varlist{i},'ans')
continue;
end
tmp=evalin('base',varlist{i});
if isa(tmp,'shallow')
% check path & filenemae
if strcmp(path, tmp.io.path(1:end-1)) & strcmp(file, tmp.io.file) % var exists already
msg=['Project is already in the workspace under the var name:' varlist{i} '; Quitting...'];
disp(msg);
shallowObj=[];
return
end
end
end
msg=['Successfully loaded shallow project ' fullfile(path,[file '.mat']) '!'];
disp(msg);
disp('');
% now loading saved classi objects attached to project
% here browse the classification folder and load all avaiable classifiers
listclassi=dir(fullfile(path,file,'classification'));
listclassi=listclassi(~contains({listclassi.name},{'.','..'}));
listclassi=listclassi(find(arrayfun(@(x) x.isdir==1,listclassi)));
% sort the classi by ending number
if numel(listclassi)
shallowObj.processing.classification=classi;
end
arr=[];
for j=1:numel(listclassi)
tmp=regexp(listclassi(j).name, '\d+$','match') ;
arr(j)=str2num(tmp{1});
end
[s ix]=sort(arr);
listclassi=listclassi(ix);
for j=1:numel(listclassi)
name=listclassi(j).name;
str=fullfile(path,file,'classification',name,[name '_classification.mat']);
if exist(str)
[classiObj msg]=classiLoad(str);
shallowObj.processing.classification(j)=classiObj;
end
end
% now loading saved processor objects attached to project
% here browse the classification folder and load all avaiable classifiers
listclassi=dir(fullfile(path,file,'processor'));
listclassi=listclassi(~contains({listclassi.name},{'.','..'}));
listclassi=listclassi(find(arrayfun(@(x) x.isdir==1,listclassi)));
% sort the classi by ending number
if numel(listclassi)
shallowObj.processing.processor=process;
end
arr=[];
for j=1:numel(listclassi)
tmp=regexp(listclassi(j).name, '\d+$','match') ;
arr(j)=str2num(tmp{1});
end
[s ix]=sort(arr);
listclassi=listclassi(ix);
for j=1:numel(listclassi)
name=listclassi(j).name;
str=fullfile(path,file,'processor',name,[name '_processor.mat']);
if exist(str)
[classiObj msg]=processLoad(str);
end
shallowObj.processing.processor(j)=classiObj;
end
% for i=1:numel(shallowObj.processing.classification)
% [pathc,filec]=shallowObj.processing.classification(i).getPath;
%
% [classiObj msg]=classiLoad(fullfile(pathc,[filec '_classification.mat']));
%
%
% end
if numel(shallowObj.fov(1).srcpath{1})~=0 % srce path has been set for at leats one FOV; update ?
disp('* Warning *');
disp('* This project contains at least one FOV wit the following path');
disp('* The current path are:*');
for i=1:numel(shallowObj.fov)
disp([shallowObj.fov(i).srcpath{1}]);
end
disp('* Need to update the path of the source images ?');
disp('* To do so, use the shallowObj.setSrcPath function');
end