Skip to content

Commit d535ec4

Browse files
author
arch
committed
add prototype to scale with anomalies
1 parent 54ac4ba commit d535ec4

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ def calculate_score(self) -> None:
240240
self.score_x = [max([x[0] for x in self.bboxes['Woman']]) - w[0] for w in self.bboxes['Woman']]
241241
self.score_y = [max([x[1] for x in self.bboxes['Woman']]) - w[1] for w in self.bboxes['Woman']]
242242

243+
# NOTE: Scaling with the anomaly function sometimes makes the result even worse
244+
# self.score_x = sp.scale_signal_with_anomalies(self.score_x, 0, 100, lower_quantile=0.05, upper_quantile=0.99999)
245+
# self.score_y = sp.scale_signal_with_anomalies(self.score_y, 0, 100, lower_quantile=0.05, upper_quantile=0.99999)
246+
243247
self.score_x = sp.scale_signal(self.score_x, 0, 100)
244248
self.score_y = sp.scale_signal(self.score_y, 0, 100)
245249

@@ -504,6 +508,7 @@ def tracking(self) -> str:
504508

505509
video.stop()
506510
self.__logger.info(status)
511+
self.calculate_score()
507512
return status
508513

509514

@@ -562,7 +567,6 @@ def run(self) -> None:
562567
# NOTE: score_y and score_x should have the same number of elements so it should be enouth to check one score length
563568
with Listener(on_press=self.on_key_press) as listener:
564569
status = self.tracking()
565-
self.calculate_score()
566570
if len(self.score_y) >= HYPERPARAMETER['min_frames']:
567571
if self.params.direction != 'x':
568572
self.scale_score(status, direction='y')

funscript_editor/algorithms/signalprocessing.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,33 @@ def scale_signal(signal :list, lower: float = 0, upper: float = 99) -> list:
1717
return [(upper - lower) * (x - min(signal)) / (max(signal) - min(signal)) + lower for x in signal]
1818

1919

20+
def scale_signal_with_anomalies(
21+
signal :list,
22+
lower: float = 0,
23+
upper: float = 99,
24+
lower_quantile: float = 0.0005,
25+
upper_quantile: float = 0.9995) -> list:
26+
""" Scale an signal (list of float or int) between given lower and upper value
27+
28+
Args:
29+
signal (list): list with float or int signal values to scale
30+
lower (float): lower scale value
31+
upper (float): upper scale value
32+
lower_quantile (float): lower quantile value to filter [0,1]
33+
upper_quantile (float): upper quantile value to filter [0,1]
34+
35+
Returns:
36+
list: list with scaled signal
37+
"""
38+
a1 = np.quantile(signal, lower_quantile)
39+
a2 = np.quantile(signal, upper_quantile)
40+
anomaly_free = np.array([x for x in signal if a1 < x < a2])
41+
anomaly_free_min = min(anomaly_free)
42+
anomaly_free_max = max(anomaly_free)
43+
scaled = [(upper - lower) * (x - anomaly_free_min) / (anomaly_free_max - anomaly_free_min) + lower for x in signal]
44+
return [min((anomaly_free_max, max((anomaly_free_min, x)) )) for x in scaled]
45+
46+
2047
def moving_average(x :list, w: int) -> list:
2148
""" Calculate moving average for given signal x with window size w
2249

0 commit comments

Comments
 (0)