-
Notifications
You must be signed in to change notification settings - Fork 42
/
runExample.m
184 lines (120 loc) · 4.4 KB
/
runExample.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
%%example script that will run the code for a set of .avi files that are
%%found in filePath
%Place path to folder containing example .avi files here
filePath = '';
%add utilities folder to path
addpath(genpath('./utilities/'));
addpath(genpath('./PCA/'));
addpath(genpath('./segmentation_alignment/'));
addpath(genpath('./t_sne/'));
addpath(genpath('./wavelet/'));
%find all avi files in 'filePath'
imageFiles = findAllImagesInFolders(filePath,'.avi');
L = length(imageFiles);
numZeros = ceil(log10(L+1e-10));
%define any desired parameter changes here
parameters.samplingFreq = 100;
parameters.trainingSetSize = 5000;
%initialize parameters
parameters = setRunParameters(parameters);
firstFrame = 1;
lastFrame = [];
%% Run Alignment
%creating alignment directory
alignmentDirectory = [filePath '/alignment_files/'];
if ~exist(alignmentDirectory,'dir')
mkdir(alignmentDirectory);
end
%run alignment for all files in the directory
fprintf(1,'Aligning Files\n');
alignmentFolders = cell(L,1);
for ii=1:L
fprintf(1,'\t Aligning File #%4i out of %4i\n',ii,L);
fileNum = [repmat('0',1,numZeros-length(num2str(ii))) num2str(ii)];
tempDirectory = [alignmentDirectory 'alignment_' fileNum '/'];
alignmentFolders{ii} = tempDirectory;
outputStruct = runAlignment(imageFiles{ii},tempDirectory,firstFrame,lastFrame,parameters);
save([tempDirectory 'outputStruct.mat'],'outputStruct');
clear outputStruct
clear fileNum
clear tempDirectory
end
%% Find image subset statistics (a gui will pop-up here)
fprintf(1,'Finding Subset Statistics\n');
numToTest = parameters.pca_batchSize;
[pixels,thetas,means,stDevs,vidObjs] = findRadonPixels(alignmentDirectory,numToTest,parameters);
%% Find postural eigenmodes
fprintf(1,'Finding Postural Eigenmodes\n');
[vecs,vals,meanValues] = findPosturalEigenmodes(vidObjs,pixels,parameters);
vecs = vecs(:,1:parameters.numProjections);
figure
makeMultiComponentPlot_radon_fromVecs(vecs(:,1:25),25,thetas,pixels,[201 90]);
caxis([-3e-3 3e-3])
colorbar
title('First 25 Postural Eigenmodes','fontsize',14,'fontweight','bold');
drawnow;
%% Find projections for each data set
projectionsDirectory = [filePath './projections/'];
if ~exist(projectionsDirectory,'dir')
mkdir(projectionsDirectory);
end
fprintf(1,'Finding Projections\n');
for i=1:L
fprintf(1,'\t Finding Projections for File #%4i out of %4i\n',i,L);
projections = findProjections(alignmentFolders{i},vecs,meanValues,pixels,parameters);
fileNum = [repmat('0',1,numZeros-length(num2str(i))) num2str(i)];
fileName = imageFiles{i};
save([projectionsDirectory 'projections_' fileNum '.mat'],'projections','fileName');
clear projections
clear fileNum
clear fileName
end
%% Use subsampled t-SNE to find training set
fprintf(1,'Finding Training Set\n');
[trainingSetData,trainingSetAmps,projectionFiles] = ...
runEmbeddingSubSampling(projectionsDirectory,parameters);
%% Run t-SNE on training set
fprintf(1,'Finding t-SNE Embedding for the Training Set\n');
[trainingEmbedding,betas,P,errors] = run_tSne(trainingSetData,parameters);
%% Find Embeddings for each file
fprintf(1,'Finding t-SNE Embedding for each file\n');
embeddingValues = cell(L,1);
for i=1:L
fprintf(1,'\t Finding Embbeddings for File #%4i out of %4i\n',i,L);
load(projectionFiles{i},'projections');
projections = projections(:,1:parameters.pcaModes);
[embeddingValues{i},~] = ...
findEmbeddings(projections,trainingSetData,trainingEmbedding,parameters);
clear projections
end
%% Make density plots
maxVal = max(max(abs(combineCells(embeddingValues))));
maxVal = round(maxVal * 1.1);
sigma = maxVal / 40;
numPoints = 501;
rangeVals = [-maxVal maxVal];
[xx,density] = findPointDensity(combineCells(embeddingValues),sigma,numPoints,rangeVals);
densities = zeros(numPoints,numPoints,L);
for i=1:L
[~,densities(:,:,i)] = findPointDensity(embeddingValues{i},sigma,numPoints,rangeVals);
end
figure
maxDensity = max(density(:));
imagesc(xx,xx,density)
axis equal tight off xy
caxis([0 maxDensity * .8])
colormap(jet)
colorbar
figure
N = ceil(sqrt(L));
M = ceil(L/N);
maxDensity = max(densities(:));
for i=1:L
subplot(M,N,i)
imagesc(xx,xx,densities(:,:,i))
axis equal tight off xy
caxis([0 maxDensity * .8])
colormap(jet)
title(['Data Set #' num2str(i)],'fontsize',12,'fontweight','bold');
end
close_parpool