-
Notifications
You must be signed in to change notification settings - Fork 0
/
just_the_tip.m
79 lines (52 loc) · 1.83 KB
/
just_the_tip.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
function [tips, numtips, Icirc1, tipidx, realnumtips] = just_the_tip(I1, I5, P)
Icirc1 = tip_filter(I1, .13);
Icirc5 = tip_filter(I5, .13);
%Find coordinates of centroids of continous areas
stats1 = regionprops(Icirc1, 'Centroid');
stats5 = regionprops(Icirc5, 'Centroid');
Ptip = [P(1,:); P(100,:)];
for i = 1:numel(stats1)
tips(i, :) = stats1(i).Centroid;
end
for i = 1:numel(stats5)
tips5(i, :) = stats5(i).Centroid;
end
tips = fliplr(tips);
tips5 = fliplr(tips5);
realnumtips = numel(stats1);
if numel(stats1) >= 2 && numel(stats5) ~= 1
numtips = numel(stats1);
D = pdist2(tips, Ptip);
[ num, tipidx] = min(D);
tip1 = tips(tipidx(1), :);
tip2 = tips(tipidx(2), :);
else
numtips = 1;
if numel(stats1) >= 2
W = pdist2(Ptip, tips5);
[ num, tipidx] = min(W);
else
W = pdist2(Ptip, tips);
[ num, tipidx] = min(W);
end
hid_tip = tricky_tip(P,I1, tipidx);
if tipidx == 1 && numel(stats1) >= 2
V = pdist2(tips, Ptip(1,:));
[num, tipidx2] = min(V);
tip1 = tips(tipidx2, :);
tip2 = hid_tip;
elseif tipidx == 2 && numel(stats1) >= 2
V = pdist2(tips, Ptip(2,:));
[num, tipidx2] = min(V);
tip2 = tips(tipidx2, :);
tip1 = hid_tip;
elseif tipidx ==1
tip2 = hid_tip;
tip1 = tips(1,:);
elseif tipidx ==2
tip2 = tips(1, :);
tip1 = hid_tip;
end
end
tips = [tip1; tip2];
end