-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_edges_boxmerkmal.m
81 lines (63 loc) · 2.16 KB
/
get_edges_boxmerkmal.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
function [edges, alpha] = get_edges_boxmerkmal(points)
x = points(:, 1);
y = points(:, 2);
k = 5;
alpha = atan2(y(1+k:end)-y(1:end-k), x(1+k:end)-x(1:end-k));
edges = [];
% angle histogram
% from 0 to 180 deg with bin size of 5 deg
borders = 0:5:180;
figure(4)
h = histogram(rad2deg(alpha), borders);
xlabel('alpha');
ylabel('Häufigkeit');
title('Winkelhistogramm');
n = h.Values;
% claculate new_alpha
a1 = (n(15)*(15*5+2.5))+(n(16)*(16*5+2.5))+(n(17)*(17*5+2.5))+(n(18)*(18*5+2.5))+(n(19)*(19*5+2.5));
a2 = n(15)+n(16)+n(17)+n(18)+n(19);
new_alpha = deg2rad(a1/a2);
disp(rad2deg(new_alpha));
R = [cos(-new_alpha), -sin(-new_alpha);
sin(-new_alpha), cos(-new_alpha)];
rotPoints = [0;0];
% rotate points
for nr = 1:size(points)
rotP = R * points(nr,:)';
rotPoints = [rotPoints, rotP];
end
% inverse matrix
rotPoints = rotPoints';
% plot X histogram
borders = -25:0.1:25;
figure(2)
histogram(rotPoints(:,1), borders);
xlabel('X');
ylabel('Häufigkeit');
title('X - Histogramm');
% get hight of bins
[counts, edgesX] = histcounts(rotPoints(:,1), 'BinWidth', 0.1);
% find the two highest peaks for X vaiues
[peakHights, peakLocation] = findpeaks(counts, 'MinPeakDistance', 50);
[sortedHights, sortedIndices] = sort(peakHights, 'descend');
topPeaks = sortedIndices(1:2);
peak1Location = peakLocation(topPeaks(1));
peak2Location = peakLocation(topPeaks(2));
XValue1 = edgesX(3);
XValue2 = edgesX(end-3);
% plot Y histogram
figure(3)
histogram(-rotPoints(:,2), borders);
xlabel('Y');
ylabel('Häufigkeit');
title('Y - Histogramm');
% get hight of bins
[counts, edgesY] = histcounts(-rotPoints(:,2), 'BinWidth', 0.1);
% find the highest peaks for Y value
[sortedCounts, sortedIndices] = sort(counts, 'descend');
topIndices = sortedIndices(1:1);
BinY = (edgesY(topIndices) + edgesY(topIndices + 1))/2;
% return edges
edges = [XValue1, BinY;
XValue2, BinY]
end