-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotDetector.m
More file actions
141 lines (107 loc) · 4.48 KB
/
plotDetector.m
File metadata and controls
141 lines (107 loc) · 4.48 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
%% 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]
%% manual_ways_toshow=[63,80,74,97];
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
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);
%% p1 = polyfit(x1,y1,1);
for j=1:length(Way_2pt)
if(i~=-j )
x2 = Way_2pt(j,1,1);
y2 = Way_2pt(j,1,2);
cell2=Way_2pt(j,4,1);
way2=Way_2pt(j,3,1);
%% 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 && cell1~=cell2)
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;
%% saveas(gcf,'CV2','jpg')
drawnow;
end
end
end
end
blocks={};
blocks1={};
block_num = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%