Skip to content

Commit ce8e3d1

Browse files
author
arch
committed
improve draft code (#10)
1 parent ea7a07c commit ce8e3d1

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

funscript_editor/algorithms/signalprocessing.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def get_edge_points(score: list, changepoints: dict, threshold: float = 150.0) -
142142
""" Get Edge Points by calculate the distance to each point in the score.
143143
144144
Note:
145-
We map the time axis for between each predicted changepoint to 0 - 100 to
146-
get usable distances.
145+
We map the time axis between each predicted changepoint to min_pos - max_pos in
146+
this section to get usable distances.
147147
148148
Args:
149149
score (list): the predicted score
@@ -154,23 +154,29 @@ def get_edge_points(score: list, changepoints: dict, threshold: float = 150.0) -
154154
list: list with index of the edge points (additional change points)
155155
"""
156156
edge_points = []
157+
overall_max_distance = 0
157158
cp = changepoints['min']+changepoints['max']
158159
cp.sort()
159160
if len(cp) < 2: return []
160161
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) \
162+
min_pos = min([score[cp[i]], score[cp[i+1]]])
163+
max_pos = max([score[cp[i]], score[cp[i+1]]])
164+
start = np.array([min_pos, score[cp[i]]])
165+
end = np.array([max_pos, score[cp[i]]])
166+
scale = lambda x: ((max_pos - min_pos) * (x - cp[i]) / float(cp[i+1] - cp[i]) + float(min_pos))
167+
distances = [ norm(np.cross(end-start, start-np.array([scale(j), score[j]])))/norm(end-start) \
164168
for j in range(cp[i], cp[i+1]) ]
165169
max_distance = max(distances)
170+
if overall_max_distance < max_distance:
171+
overall_max_distance = max_distance
166172
if max_distance > threshold:
167173
print("Add Edge point for distance", max_distance)
168174
edge_points.append(cp[i] + distances.index(max_distance))
169175

176+
print("Max distance was", overall_max_distance)
170177
return edge_points
171178

172179

173-
174180
def get_local_max_and_min_idx(score :list, fps: int, shift_min :int = 0, shift_max :int = 0) -> dict:
175181
""" Get the local max and min positions in given signal
176182

0 commit comments

Comments
 (0)