-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_distances.m
67 lines (59 loc) · 2.45 KB
/
generate_distances.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
% for each letter file
clear;
clc;
cd ~/Documents/MATH149/matlab_examples; % move to location of load_javaplex.m
load_javaplex;
cd ~/Documents/MATH149/git; % back to project home
filenames = [];
num_letters = [];
for ch = 'A':'Z'
files = dir(fullfile('~','Documents', 'MATH149', 'git', 'Letters', ch, '*.jpg'));
for f = 1:size(files,1)
filenames = [filenames; fullfile('~','Documents', 'MATH149', 'git', 'Letters', ch, files(f).name), ' '];
end
num_letters = [num_letters, size(files,1)];
end
for ch = 'a':'z'
files = dir(fullfile('~','Documents', 'MATH149', 'git', 'Letters', strcat(ch,'_'), '*.jpg'));
for f = 1:size(files,1)
filenames = [filenames; fullfile('~','Documents', 'MATH149', 'git', 'Letters', strcat(ch,'_'), files(f).name)];
end
num_letters = [num_letters, size(files,1)];
end
codes = javaArray('edu.stanford.math.plex4.homology.barcodes.AnnotatedBarcodeCollection', sum(num_letters), 5);
pers = edu.stanford.math.plex4.api.Plex4.getModularSimplicialAlgorithm(2, 2);
max_dimension = 2;
nu = 1;
num_divisions = 100;
for s = 1:sum(num_letters)
pc1 = get_pointcloud(strtrim(filenames(s,:)));
pc2 = rotate90(pc1);
pc3 = rotate90(pc2);
pc4 = rotate90(pc3);
% landmark_selector = api.Plex4.createMaxMinSelector(pc1, int32(size(pc1,1)/5));
% R = landmark_selector.getMaxDistanceFromPointsToLandmarks();
% max_filtration = 2 * R;
% stream5 = streams.impl.LazyWinessStream(landmark_selector.getUnderlyingMetricSpace(), landmark_selector, max_dimension, max_filtration, nu, num_divisions);
map1 = get_vertex_points_map(pc1);
map2 = get_vertex_points_map(pc2);
map3 = get_vertex_points_map(pc3);
map4 = get_vertex_points_map(pc4);
kmap1 = get_vertex_points_map(pc1);
stream1 = connect_vertices(map1);
stream2 = connect_vertices(map2);
stream3 = connect_vertices(map3);
stream4 = connect_vertices(map4);
codes(s, 1) = pers.computeAnnotatedIntervals(stream1);
codes(s, 2) = pers.computeAnnotatedIntervals(stream2);
codes(s, 3) = pers.computeAnnotatedIntervals(stream3);
codes(s, 4) = pers.computeAnnotatedIntervals(stream4);
%codes(s, 5) = pers.computeAnnotatedIntervals(stream5);
end
distances = zeros(sum(num_letters));
for row = 1:sum(num_letters)
for col = row:sum(num_letters)
distances(row, col) = distance(codes(row,1:4), codes(col,1:4));
end
end
distances = distances + distances';
dlmwrite('distances_harmonic', distances)