Skip to content

Commit ea7a07c

Browse files
author
arch
committed
add draft code for edge point detection (#10)
1 parent 0326470 commit ea7a07c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

funscript_editor/algorithms/signalprocessing.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import platform
66
from funscript_editor.utils.config import HYPERPARAMETER, SETTINGS
7+
from numpy.linalg import norm
78

89
def scale_signal(signal :list, lower: float = 0, upper: float = 99) -> list:
910
""" Scale an signal (list of float or int) between given lower and upper value
@@ -137,6 +138,39 @@ def get_changepoints(score: list, fps: int, alpha: float) -> list:
137138
return changepoints
138139

139140

141+
def get_edge_points(score: list, changepoints: dict, threshold: float = 150.0) -> list:
142+
""" Get Edge Points by calculate the distance to each point in the score.
143+
144+
Note:
145+
We map the time axis for between each predicted changepoint to 0 - 100 to
146+
get usable distances.
147+
148+
Args:
149+
score (list): the predicted score
150+
changepoints (dict): current min and max changepoints
151+
threshold (float): threshold value to predict additional edge point
152+
153+
Returns:
154+
list: list with index of the edge points (additional change points)
155+
"""
156+
edge_points = []
157+
cp = changepoints['min']+changepoints['max']
158+
cp.sort()
159+
if len(cp) < 2: return []
160+
for i in range(len(cp)-1):
161+
start = np.array([0.0, score[cp[i]]])
162+
end = np.array([100.0, score[cp[i]]])
163+
distances = [ norm(np.cross(end-start, start-np.array([100.0 * (j - cp[i]) / (cp[i+1] - cp[i]), score[j]])))/norm(end-start) \
164+
for j in range(cp[i], cp[i+1]) ]
165+
max_distance = max(distances)
166+
if max_distance > threshold:
167+
print("Add Edge point for distance", max_distance)
168+
edge_points.append(cp[i] + distances.index(max_distance))
169+
170+
return edge_points
171+
172+
173+
140174
def get_local_max_and_min_idx(score :list, fps: int, shift_min :int = 0, shift_max :int = 0) -> dict:
141175
""" Get the local max and min positions in given signal
142176

0 commit comments

Comments
 (0)