-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotDetector.m
More file actions
220 lines (169 loc) · 6.61 KB
/
plotDetector.m
File metadata and controls
220 lines (169 loc) · 6.61 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
%% load data into matlab
hold on
close all
clear all
load('cellarray_ways.mat', 'cellarray_ways');
%Ways = zeros(length(cellarray_ways),length(cellarray_ways{cell_num}),2);
%% find block
for cell_num = 1:length(cellarray_ways)
for point_num = 1:length(cellarray_ways{cell_num})
Ways(cell_num,point_num,1) = cellarray_ways{cell_num}{point_num}(1);
Ways(cell_num,point_num,2) = cellarray_ways{cell_num}{point_num}(2);
end
end
%% load data into matlab
load('cellarray_ways.mat', 'cellarray_ways');
%Ways = zeros(length(cellarray_ways),length(cellarray_ways{cell_num}),2);
%% find block
for cell_num = 1:length(cellarray_ways)
for point_num = 1:length(cellarray_ways{cell_num})
Ways(cell_num,point_num,1) = cellarray_ways{cell_num}{point_num}(1);
Ways(cell_num,point_num,2) = cellarray_ways{cell_num}{point_num}(2);
end
end
hold on
X={};
Y={};
for cell_num = 1:length(cellarray_ways)
%plot(Ways(cell_num,:,1) , Ways(cell_num,:,2));
manual_ways_toshow=[1:319]
if (sum(cell_num==manual_ways_toshow)==1)
disp([num2str(cell_num) ,'_']);
%following code is used to detect if the path(set of points) is a
%relatively straight line
[p,struct] = polyfit( Ways(cell_num,1:length(cellarray_ways{cell_num}),1) , Ways(cell_num,1:length(cellarray_ways{cell_num}),2) ,1)
if(struct.df<900000 )% .df is a measure of straightness (dont know/need the exact details)
plot( Ways(cell_num,1:length(cellarray_ways{cell_num}),1) , Ways(cell_num,1:length(cellarray_ways{cell_num}),2) ,'g');
X{end+1}= Ways(cell_num,1:length(cellarray_ways{cell_num}),1);
Y{end+1}= Ways(cell_num,1:length(cellarray_ways{cell_num}),2);
%dont plot lines that arent straight
disp('is not a st line')
end
% number the lines for easy marking of paths
text(max(Ways(cell_num,1:length(cellarray_ways{cell_num}),1)),max(Ways(cell_num,1:length(cellarray_ways{cell_num}),2)),num2str(cell_num))
disp('^');
end
end
%% making 2 point ways
Way_2pt =[];
id=0;
for cell_num = 1:length(cellarray_ways)
curWayLen = length(cellarray_ways{cell_num});
for iter = 1:curWayLen
if iter+1 <= curWayLen
id=id+1;
%starting point
Way_2pt(end+1 ,1 ,1) = Ways(cell_num,iter,1);
Way_2pt(end ,1 ,2) = Ways(cell_num,iter,2);
Way_2pt(end ,3,1) = cell_num;
Way_2pt(end , 4 , 1)=id;
%ending point
Way_2pt(end , 2 , 1)= Ways(cell_num,iter+1,1);
Way_2pt(end , 2 , 2)= Ways(cell_num,iter+1,2);
x=[ Ways(cell_num,iter,1);,Ways(cell_num,iter+1,1)];
y=[ Ways(cell_num,iter,2);,Ways(cell_num,iter+1,2)];
%% plot(x,y)
end
end
end
compare = @(n1,n2,n_dcp) round(n1*10^n_dcp)==round(n2*10^n_dcp);
count = 0;
intersections=[];
for i=1:length(Way_2pt)
x1 = Way_2pt(i,2,1);
y1 = Way_2pt(i,2,2);
cell1=Way_2pt(i,4,1);
way1=Way_2pt(i,3,1);
x4 = Way_2pt(i,1,1);
y4 = Way_2pt(i,1,2);
%% p1 = polyfit(x1,y1,1);
for j=1:length(Way_2pt)
done = 0;
x2 = Way_2pt(j,1,1);
y2 = Way_2pt(j,1,2);
cell2=Way_2pt(j,4,1);
way2=Way_2pt(j,3,1);
x3 = Way_2pt(j,2,1);
y3 = Way_2pt(j,2,2);
%% diff_tocmp= tocmp_way_end-tocmp_way_start;
%%slope_in=diff_tocmp(2)/diff_tocmp(1);
%%% p2 = polyfit(x2,y2,1);
%% x_intersect = fzero(@(x) polyval(p1-p2,x),3);
%% y_intersect = polyval(p1,x_intersect);
%% if(((abs(x_intersect-min(x2))<0.001 &&abs(x_intersect-min(x1))<0.001) || (abs(x_intersect-max(x2))<0.001 && abs(x_intersect-max(x1))<0.001)) && ((abs(y_intersect-min(y2))<0.001 && abs(y_intersect-min(y1))<0.001) ||( abs(y_intersect-max(y2))<0.001 && abs(y_intersect-max(y1))<0.001)))
if (x1==x2 && y1 == y2 && way1~=way2 )
done = 1;
count=count+1;
intersections(count,1)=x1;
intersections(count,2)=y1;
intersections(count,3)=cell1;
intersections(count,4)=cell2;
intersections(count,5)=way1;
intersections(count,6)=way2;
intersections(count,7)=0;
%% saveas(gcf,'CV2','jpg')
drawnow;
end
if (x1==x3 && y1 == y3 && way1~=way2 && done == 0 )
count=count+1;
done = 1;
intersections(count,1)=x1;
intersections(count,2)=y1;
intersections(count,3)=cell1;
intersections(count,4)=cell2;
intersections(count,5)=way1;
intersections(count,6)=way2;
intersections(count,7)=0;
%% saveas(gcf,'CV2','jpg')
drawnow;
end
if (x2==x4 && y2 == y4 && way1~=way2 && done == 0 )
count=count+1;
intersections(count,1)=x2;
intersections(count,2)=y2;
intersections(count,3)=cell1;
intersections(count,4)=cell2;
intersections(count,5)=way1;
intersections(count,6)=way2;
intersections(count,7)=0;
done = 1;
%% saveas(gcf,'CV2','jpg')
drawnow;
end
if (x3==x4 && y3 == y4 && way1~=way2 && done == 0 )
count=count+1;
done = 1;
intersections(count,1)=x3;
intersections(count,2)=y3;
intersections(count,3)=cell1;
intersections(count,4)=cell2;
intersections(count,5)=way1;
intersections(count,6)=way2;
intersections(count,7)=0;
%% saveas(gcf,'CV2','jpg')
drawnow;
end
end
end
blocks={};
blocks1={};
block_num = 0;
ways1 = intersections(:,5);
ways2 = intersections(:,6);
intersections2 = [];
count2= 0;
for i = 1:length(cellarray_ways)
for j = i+1 : length(cellarray_ways)
for k = 1: length(intersections)
tmp = intersections(k,:);
if (tmp(5) == i && tmp(6) == j) || (tmp(6) == i && tmp(5) == j)
count2 = count2 + 1;
intersections2(count2,:) = tmp;
k = length(intersections);
j = length(cellarray_ways);
end
end
end
end
intersections = intersections2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%