-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbatchMergeTileBuffer.m
72 lines (45 loc) · 1.52 KB
/
batchMergeTileBuffer.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
function batchMergeTileBuffer(f)
% batchMergeTileBuffer: mergeTileBuffer to all neighboring files
%
% batchMergeTileBuffer(f) where f is a cellstr of files to be merged.
% Filenames must be in the format /rr_cc_*.mat where rr and cc are the
% tile row and column numbers.
[~,fname]=cellfun(@fileparts, f, 'UniformOutput',false);
% tile row/col index from filename
tc = char(fname(:));
tr= str2num(tc(:,1:2));
tc= str2num(tc(:,4:5));
% get up/down/right/left neighbors
A = [[0 1];[1 0];[-1 0];[0 -1]];
% pair counter
c=0;
% pair index variables
n0=0;
n1=0;
% loop through each file and see if neighbors exist, only keeping unique
% pairs
i=1;
for i=1:length(f);
% this row_col string
si=[num2str(tr(i),'%02d'),'_',num2str(tc(i),'%02d')];
j=1;
for j=1:4
% that row_col string
sj=[num2str(tr(i)+A(j,1),'%02d'),'_',num2str(tc(i)+A(j,2),'%02d')];
% make filename
fj=strrep(f{i},si,sj);
% test if it exists in list
n = find(strcmp(fj,f));
if ~isempty(n)
% exists, but is it aleady matched?
[~,ia]=intersect([n i],[n0 n1],'rows');
if ~isempty(ia); continue; end
% new pair, add to count and vectors
c=c+1;
n0(c,1)=i;
n1(c,1)=n;
end
end
end
% run mergeTileBuffer on each pair in list
for i=1:length(n0); mergeTileBuffer(f{n0(i)},f{n1(i)}); end