-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate_A_scan_ROI.m
executable file
·117 lines (90 loc) · 4.6 KB
/
update_A_scan_ROI.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
function update_A_scan_ROI(directory, file_list, oct_extension)
%% HOUSEKEEPING
if nargin == 0
directory = fullfile('.', 'data');
oct_extension = 'img'; % TODO! update if you have mixed exts
s = dir(fullfile(directory, ['*.', oct_extension]));
file_list = {s.name}';
end
curr_path = mfilename('fullpath');
[curr_dir,filename,ext] = fileparts(curr_path);
if isempty(curr_dir); curr_dir = pwd; end
cd(curr_dir)
% shared config for all the files
config = read_config();
no_of_files = length(file_list);
%% Create the file listing for disk, and backup if needed
fileOut = fullfile(directory, config.file_listing_txt);
file_specs_empty = 0;
% if the text file exists alread
if exist(fileOut, 'file') == 2
disp(['The text file "', config.file_listing_txt, '" already exists'])
% make backup
datestring = datestr(now);
datestring = strrep(datestring, ':', '');
datestring = strrep(datestring, '-', '');
datestring = strrep(datestring, ' ', '');
% if you want to keep multiple backups without
% overwriting
source = fileOut;
destination = [fileOut, '.', datestring, '.bak.txt'];
[status,message,messageId] = copyfile(source, destination);
% check if there are new files
file_specs = get_file_specs(directory, config.file_listing_txt);
else
disp('This is the first time that you create file listing for this folder, correct?')
file_specs_empty = 1;
end
%% Create cell for ouput
z_min = config.crop_z_window(1);
z_max = config.crop_z_window(2);
left_min = config.crop_left_eye(1);
left_max = config.crop_left_eye(2);
right_min = config.crop_right_eye(1);
right_max = config.crop_right_eye(2);
for file = 1 : no_of_files
% the files with custom coordinates already
if file_specs_empty == 0
try
coords_ind = check_if_coords(file_list{file}, file_specs.filename);
catch err
if strcmp(err.identifier, 'MATLAB:table:UnrecognizedVarName')
% for now some reason, the headers are gone and we
% cannot reference with the field names?
error('header fields are just as var1 / var2 / var3 / etc., they would need to have actually the variable names')
else
err
end
end
else
coords_ind = [];
end
if isempty(coords_ind)
disp(['+ New file = ', file_list{file}, ' detected, initialized with fixed coordinates to: ', config.file_listing_txt])
output_cell{file, 1} = file_list{file};
output_cell{file, 2} = z_min;
output_cell{file, 3} = z_max;
output_cell{file, 4} = left_min;
output_cell{file, 5} = left_max;
output_cell{file, 6} = right_min;
output_cell{file, 7} = right_max;
else
disp(['| Not changing the coordinate values for ', file_list{file}])
% Strictly speaking we are reading the contents of the file
% and then writing on the text file, so if there are some
% weird I/O problems, you will start to get garbage on your
% text files.
output_cell{file, 1} = file_specs.filename{file};
output_cell{file, 2} = file_specs.z_min(file);
output_cell{file, 3} = file_specs.z_max(file);
output_cell{file, 4} = file_specs.left_min(file);
output_cell{file, 5} = file_specs.left_max(file);
output_cell{file, 6} = file_specs.right_min(file);
output_cell{file, 7} = file_specs.right_max(file);
% TODO! Check first if there are _ANY_ new files, and then
% determine if something needs to be done, as now every
% time some files values are written
end
end
%% Write to disk
write_coords_to_disk(fileOut, output_cell)