forked from OpenPIV/openpiv-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readImDir.m
301 lines (234 loc) · 10.1 KB
/
readImDir.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
function varargout = readImDir(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @readImDir_OpeningFcn, ...
'gui_OutputFcn', @readImDir_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})%#ok<AND2>
% str2func(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% --- Executes just before readImDir is made visible.
function readImDir_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to readImDir (see VARARGIN)
% Choose default command line output for readImDir
handles = guihandles;
handles.output = hObject;
if exist('lastpath.mat','file')
load('lastpath.mat');
if exist('lastpath','var') && exist(lastpath,'dir')
handles.path = lastpath;
else
handles.path = pwd;
end
else
handles.path = pwd;
end
handles.state3d = 0;
% Update handles structure
guidata(hObject, handles);
update_gui(hObject,[],handles);
% %
% % % UIWAIT makes readImDir wait for user response (see %uiresume)
uiwait(handles.fig);
% --- Outputs from this function are returned to the command line.
function varargout = readImDir_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
% if nargout
if isfield(handles,'filenames')
varargout{1} = handles.filenames;
varargout{2} = handles.path;
% varargout{3} = handles.dT*handles.step;
% varargout{4} = handles.scale;
% varargout{5} = handles.state3d;
else
varargout{1} = {};
varargout{2} = {};
end
close(handles.fig);
% --- Executes on button press in pushbutton_load.
function pushbutton_load_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_load (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Returns the names of the selected files
handles.list_entries = get(handles.listbox_files,'String');
handles.index_selected = get(handles.listbox_files,'Value');
% jump = int32(str2num(get(handles.jump,'String')));
jump = 1;
if isempty(handles.index_selected) | min(handles.index_selected) < 3
errordlg('Wrong selection','Incorrect Selection','modal')
else
switch length(handles.index_selected)
case {1} % only the first file is selected,
index = handles.index_selected;
handles.filenames = handles.list_entries(index(1:jump:end));
case {2}
index = handles.index_selected; %
handles.filenames = handles.list_entries(index(1:jump:end));
otherwise
handles.filenames = handles.list_entries(handles.index_selected(1:jump:end));
end
try
lastpath = handles.path;
save('lastpath.mat','lastpath');
catch
;
end
guidata(hObject,handles);
uiresume(handles.fig);
end
% --- Executes on button press in pushbutton_cancel.
function pushbutton_cancel_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_cancel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
uiresume(handles.fig);
% --- Executes during object creation, after setting all properties.
function listbox_files_CreateFcn(hObject, eventdata, handles)
% --- Executes on selection change in listbox_files.
function listbox_files_Callback(hObject, eventdata, handles)
if strcmp(get(handles.fig,'SelectionType'),'open') % If double click
index_selected = get(handles.listbox_files,'Value');
file_list = get(handles.listbox_files,'String');
filename = file_list{index_selected}; % Item selected in list box
% keyboard
if isdir([handles.path,filesep,filename]) % If directory
if index_selected == 2
handles.path = handles.path(1:max(findstr(handles.path,filesep)-1));
elseif index_selected > 2
handles.path = [handles.path,filesep,filename];
end
guidata(handles.fig,handles);
update_gui(handles.fig,[],handles);
end
end
% --- Executes during object creation, after setting all properties.
function edit_path_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_path (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
handles = guihandles;
if ~isfield(handles,'path')
handles.path = cd;
end
set(hObject,'String',handles.path);
guidata(hObject,handles);
function edit_path_Callback(hObject, eventdata, handles)
% hObject handle to edit_path (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_path as text
% str2double(get(hObject,'String')) returns contents of edit_path as a double
tmp = get(hObject,'String');
if isdir(tmp)
handles.path = tmp;
else
set(hObject,'String',handles.path);
end
guidata(hObject,handles);
update_gui(hObject, [], handles);
% --- Executes on button press in pushbutton_cd.
function pushbutton_cd_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_cd (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tmp = uigetdir(handles.path);
if tmp > 0 & isdir(tmp), handles.path = tmp; end
set(handles.edit_path,'String',handles.path);
guidata(hObject, handles);
update_gui(hObject, [], handles);
function edit_scale_Callback(hObject, eventdata, handles)
% hObject handle to edit_scale (see GCBO) eventdata reserved - to be
% defined in a future version of MATLAB handles structure with handles
% and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_scale as text
% str2double(get(hObject,'String')) returns contents of edit_scale
% as a double
if isnan(str2double(get(hObject,'String')))
set(hObject,'String','1');
end
handles.scale = str2double(get(hObject,'String'));
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function fig_CreateFcn(hObject, eventdata, handles)
% hObject handle to fig (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
handles = guihandles(hObject);
movegui(hObject,'northwest')
% --- Executes on button press in pushbutton_updir.
function pushbutton_updir_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_updir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s = handles.path;
s = s(1:max(3,max(findstr(s,filesep))-1));
if exist(s,'dir')
handles.path = s;
end
guidata(hObject,handles);
update_gui(hObject,[],handles);
function update_gui(hObject, eventdata, handles)
% Self made UPDATE GUI function
image_files = {'jpg','bmp','jpeg','tif','tiff','png'};
if ~isdir(handles.path)
handles.path = cd;
end
set(handles.edit_path,'String',handles.path);
list = dir(handles.path);
handles.files = {};
for i = 1:length(list)
if ismember(lower(getext(list(i).name)),image_files)
handles.files = cat(1,handles.files,list(i).name);
end
end
% handles.files = dir(fullfile(handles.path,'*.bmp'));
% handles.files = cat(1,handles.files,dir(fullfile(handles.path,'*.jpg')));
% handles.files = cat(1,handles.files,dir(fullfile(handles.path,'*.jpeg')));
% handles.files = cat(1,handles.files,dir(fullfile(handles.path,'*.tif')));
% handles.files = cat(1,handles.files,dir(fullfile(handles.path,'*.tiff')));
% handles.files = cat(1,handles.files,dir(fullfile(handles.path,'*.png')));
% list = dir(handles.path);
ind = find(cat(1,list.isdir));
set(handles.fig,'SelectionType','normal');
set(handles.listbox_files,'String',{list(ind).name,handles.files{:}},'Value',1);
guidata(handles.fig, handles);
function jump_Callback(hObject, eventdata, handles)
% hObject handle to jump (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of jump as text
% str2double(get(hObject,'String')) returns contents of jump as a double
% --- Executes during object creation, after setting all properties.
function jump_CreateFcn(hObject, eventdata, handles)
% hObject handle to jump (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end