Skip to content

Commit 3dd6ed8

Browse files
author
arch
committed
improve changepoint positions
1 parent c27c8a3 commit 3dd6ed8

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

funscript_editor/algorithms/signalprocessing.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,45 @@ def get_local_max_and_min_idx(score :list, fps: int, shift_min :int = 0, shift_m
7575
dict: dict with 2 lists with all local max and min indexes ({'min':[], 'max':[]})
7676
"""
7777
avg = moving_average(score, w=round(fps * HYPERPARAMETER['avg_sec_for_local_min_max_extraction']))
78-
result = {'min': [], 'max': []}
78+
changepoints = {'min': [], 'max': []}
7979
tmp_min_idx, tmp_max_idx = -1, -1
8080
for pos in range(len(score)):
8181
if score[pos] < avg[pos]:
8282
if tmp_min_idx < 0: tmp_min_idx = pos
8383
elif score[tmp_min_idx] >= score[pos]: tmp_min_idx = pos
8484
elif tmp_min_idx >= 0:
85-
if tmp_min_idx >= -1*shift_min and tmp_min_idx + shift_min < len(score):
86-
result['min'].append(tmp_min_idx + shift_min)
87-
else:
88-
result['min'].append(tmp_min_idx)
85+
changepoints['min'].append(tmp_min_idx)
8986
tmp_min_idx = -1
9087

9188
if score[pos] > avg[pos]:
9289
if tmp_max_idx < 0: tmp_max_idx = pos
9390
elif score[tmp_max_idx] <= score[pos]: tmp_max_idx = pos
9491
elif tmp_max_idx >= 0:
95-
if tmp_max_idx >= -1*shift_max and tmp_max_idx + shift_max < len(score):
96-
result['max'].append(tmp_max_idx + shift_max)
97-
else:
98-
result['max'].append(tmp_max_idx)
92+
changepoints['max'].append(tmp_max_idx)
9993
tmp_max_idx = -1
100-
return result
94+
95+
delta = (max(score) - min(score)) * 0.01 * min((10.0, float(HYPERPARAMETER['local_max_min_delta_in_percent']) ))
96+
97+
# shift points to the real change points
98+
for k, idx in enumerate(changepoints['min']):
99+
new_pos = idx
100+
while new_pos+1 < len(score) and score[idx] + delta > score[new_pos+1]:
101+
new_pos += 1
102+
changepoints['min'][k] = new_pos
103+
104+
for k, idx in enumerate(changepoints['max']):
105+
new_pos = idx
106+
while new_pos+1 < len(score) and score[idx] - delta < score[new_pos+1]:
107+
new_pos += 1
108+
changepoints['max'][k] = new_pos
109+
110+
# apply shift
111+
if shift_min != 0:
112+
for k, idx in enumerate(changepoints['min']):
113+
changepoints['min'][k] = max((0, min((len(score)-1, idx+shift_min)) ))
114+
115+
if shift_max != 0:
116+
for k, idx in enumerate(changepoints['max']):
117+
changepoints['max'][k] = max((0, min((len(score)-1, idx+shift_max)) ))
118+
119+
return changepoints

funscript_editor/config/hyperparameter.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
# This parameter specifies how many frames are skipped and interpolated during tracking.
88
# Increase this parameter to improve the processing speed on slow hardware. But higher
99
# values result in poorer predictions!
10-
skip_frames: 0
10+
skip_frames: 1
1111

1212
# Specify the window size for the calculation of the reference value for the local min
1313
# and max search.
1414
avg_sec_for_local_min_max_extraction: 2.0
1515

16+
# Specify the maximum deviation for a min and max point in percent
17+
local_max_min_delta_in_percent: 1.0
18+
1619
# Specify the minimum required frames for the tracking. Wee need this parameter to
1720
# ensure there is at leas two strokes in the tracking result.
1821
min_frames: 100

0 commit comments

Comments
 (0)