-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperFillMissingViews.m
More file actions
54 lines (46 loc) · 2.08 KB
/
helperFillMissingViews.m
File metadata and controls
54 lines (46 loc) · 2.08 KB
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
function filledImageFiles = helperFillMissingViews(imageFiles)
% Extract all unique view identifiers from all cameras.
allViewIdentifiers = [];
for i = 1:numel(imageFiles)
% Extract view identifiers from filenames.
viewIdentifiers = helperExtractViewIdentifiers(imageFiles{i});
allViewIdentifiers = union(allViewIdentifiers,viewIdentifiers);
end
% Initialize the filled image files cell array.
filledImageFiles = cell(size(imageFiles));
% Fill missing views with empty strings.
for i = 1:numel(imageFiles)
% Extract view identifiers for the current camera.
currentFiles = imageFiles{i};
currentViewIdentifiers = helperExtractViewIdentifiers(currentFiles);
% Initialize a cell array to store aligned filenames.
filledFiles = strings(numel(allViewIdentifiers),1);
% Match views using identifiers and fill missing entries with empty strings.
for j = 1:numel(allViewIdentifiers)
viewID = allViewIdentifiers(j);
matchIndex = find(currentViewIdentifiers == viewID,1);
if ~isempty(matchIndex)
filledFiles(j) = currentFiles(matchIndex);
else
% Fill missing view with an empty string.
filledFiles(j) = "";
end
end
% Assign the aligned and filled files to the output cell array.
filledImageFiles{i} = filledFiles;
end
filledImageFiles = cat(2,filledImageFiles{:});
function viewIdentifiers = helperExtractViewIdentifiers(fileNames)
% Example of extracting view numbers from filenames.
% Assumes filenames are in the format "view<number>.ext".
viewIdentifiers = zeros(numel(fileNames),1);
for k = 1:numel(fileNames)
[~,name] = fileparts(fileNames{k});
% Extract the numeric part of the filename.
numStr = regexp(name,"\d+","match");
if ~isempty(numStr)
viewIdentifiers(k) = str2double(numStr{1});
end
end
end
end