-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlotTracks.m
139 lines (113 loc) · 4.88 KB
/
PlotTracks.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
function out_fig = PlotTracks(tracks, movie_features, varargin)
% Plot the given tracks on a schematic representatation of the plate.
% Accepts various optional arguments, most importantly 'SegmentWithFps',
% which shows the track as it is segmented.
p = inputParser;
addParameter(p, 'IndexLabels', -1);
addParameter(p, 'MarkIndexes', {});
addParameter(p, 'MarkSymbol', 'x');
addParameter(p, 'SegmentWithFps', -1); % TODO: we don't need to pass the FPS as an explicit parameter anymore, since it's included in movie_features.
addParameter(p, 'OmitIndexing', true);
addParameter(p, 'OmitKinks', true); % TODO: kinks aren't a thing anymore in our code. Consider removing.
addParameter(p, 'OmitSharpTurns', true);
% TODO: smoothing should not longer be necessary (or, at least, should be
% implemented differnetly.
addParameter(p, 'Smoothing', 'None'); % Can also take 'Add' and 'Only'
parse(p, varargin{:});
out_fig = figure;
hold on;
viscircles([movie_features.plate{1}; movie_features.drop{1}], [movie_features.plate{2}; movie_features.drop{2}]);
for ix = 1:length(tracks)
track = tracks(ix);
if isfield(track, 'filteredPath')
fp = track.filteredPath(:,2:3);
else
fp = track.path(:,2:3);
end
if strcmp(p.Results.Smoothing, 'Only')
plot(smooth(fp(:,1)), smooth(fp(:,2)));
continue
end
plot(fp(:,1), fp(:,2));
if p.Results.IndexLabels ~= -1
arrayfun(@(i) text(fp(i, 1), fp(i, 2), num2str(i)), 1:p.Results.IndexLabels:length(fp));
end
if ~isempty(p.Results.MarkIndexes)
if ~iscell(p.Results.MarkIndexes)
mark_indexes = p.Results.MarkIndexes;
else
mark_indexes = p.Results.MarkIndexes{ix};
end
plot(fp(mark_indexes,1), fp(mark_indexes,2), p.Results.MarkSymbol);
end
if p.Results.SegmentWithFps > 0
segments_vector = SegmentTrackPath(track, p.Results.SegmentWithFps);
% Paint long runs green
[long_runs, long_run_count] = SegmentVector(bitand(segments_vector, SegmentMasks.LongRun) > 0);
for segment_ix = 1:long_run_count
if ~long_runs(segment_ix,3)
continue
end
start_point_ix = long_runs(segment_ix,1);
end_point_ix = long_runs(segment_ix,2) + 1;
plot(fp(start_point_ix:end_point_ix,1), ...
fp(start_point_ix:end_point_ix,2), ...
'g');
start_point = fp(start_point_ix,:);
end_point = fp(end_point_ix,:);
if ~p.Results.OmitIndexing
text(start_point(1), start_point(2), num2str(start_point_ix));
text(end_point(1), end_point(2), num2str(end_point_ix));
end
end
% Paint pirouttes red
% Or, anything that's between a long run!
% [pirouttes, pirouette_count] = SegmentVector(bitand(segments_vector, double(bitcmp(uint8(SegmentMasks.LongRun)))) > 0);
for segment_ix = 1:long_run_count
if long_runs(segment_ix,3)
continue
end
start_point_ix = long_runs(segment_ix,1);
end_point_ix = long_runs(segment_ix,2) + 1;
plot(fp(start_point_ix:end_point_ix,1), ...
fp(start_point_ix:end_point_ix,2), ...
'r');
pirouette_start = start_point_ix;
pirouette_end = end_point_ix - 1;
points_count = 6;
if segment_ix > 1
before_origin = fp(pirouette_start - points_count,:);
plot([before_origin(1) fp(pirouette_start,1)],...
[before_origin(2) fp(pirouette_start,2)],...
'b');
end
if segment_ix < long_run_count
after_origin = fp(pirouette_end+1,:);
plot([after_origin(1) fp(pirouette_end+1+points_count,1)],...
[after_origin(2) fp(pirouette_end+1+points_count,2)],...
'b');
end
end
if ~p.Results.OmitSharpTurns
% Mark sharp turns as Xs
sharp_turns = bitand(segments_vector, SegmentMasks.SharpTurn) > 0;
plot(fp(sharp_turns,1), fp(sharp_turns,2), 'x');
end
if ~p.Results.OmitKinks
% Mark kinks as Os
kinks = bitand(segments_vector, SegmentMasks.Kink) > 0;
plot(fp(kinks,1), fp(kinks,2), 'o');
end
end
if p.Results.SegmentWithFps < 0 || p.Results.OmitIndexing
% Mark start and end of tracks:
text(fp(1,1), fp(1,2), '1');
[steps, ~] = size(fp);
text(fp(end,1), fp(end,2), num2str(steps));
end
if strcmp(p.Results.Smoothing, 'Add')
plot(smooth(fp(:,1)), smooth(fp(:,2)));
end
pbaspect([1 1 1]);
end
end