-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcowsay.py
More file actions
64 lines (49 loc) · 2.04 KB
/
cowsay.py
File metadata and controls
64 lines (49 loc) · 2.04 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
import numpy as np
intensity = np.array([1,2,3,10,10,3,2,1])
normal = np.array([1, 1, 1, 1, 2, 1, 1, 3, 1])
curvature = np.array([1, 1, 1, 1, 2, 1, 1, 1, 4])
distance_to_dtm = np.array([10, 12, 5, 3, 6, 1, 2, 1, 30])
def determine_threshold(intensity):
"""
Determines the threshold value for separating the road markings from the road surface based on the intensity values.
:param intensity: The intensity values of the points in the neighborhood. Must have shape :math:`(N)` where `N = number of points`.
:type intensity: numpy.ndarray
:return: The threshold value for separating the road markings from the road surface.
:rtype: float
"""
# Create a histogram of the intensity values
hist, bins = np.histogram(intensity, bins=5)
# Find the peak of the histogram
peak_index = np.argmax(hist)
peak_value = bins[peak_index]
# Find the valley to the left of the peak
left_hist = hist[:peak_index]
left_bins = bins[:peak_index]
left_valley_index = np.argmin(left_hist)
left_valley_value = left_bins[left_valley_index]
# Find the valley to the right of the peak
right_hist = hist[peak_index:]
right_bins = bins[peak_index:]
right_valley_index = np.argmin(right_hist)
right_valley_value = right_bins[right_valley_index]
# Choose the threshold value as the midpoint between the two valleys
threshold = (left_valley_value + right_valley_value) / 2
return threshold
def calculate_threshold(data):
"""
Calculates a threshold value based on the mean and standard deviation of the data.
:param data: The data to calculate the threshold value for.
:type data: numpy.ndarray
:return: The threshold value.
:rtype: float
"""
# Calculate the mean and standard deviation of the data
mean = np.mean(data)
std = np.std(data)
# Calculate the threshold value as the mean plus one standard deviation
threshold = mean + std
return threshold
threshold = calculate_threshold(intensity)
print(threshold)
var = np.var(intensity, axis=0)
print(var)