Skip to content
Snippets Groups Projects
Commit a2aa6286 authored by Christian's avatar Christian
Browse files

Added smoothing in line shown to user

parent 1c77de04
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,9 @@ import sys ...@@ -2,6 +2,9 @@ import sys
import math import math
import numpy as np import numpy as np
# NEW IMPORT
from scipy.signal import savgol_filter
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QApplication, QMainWindow, QGraphicsView, QGraphicsScene, QApplication, QMainWindow, QGraphicsView, QGraphicsScene,
QGraphicsEllipseItem, QGraphicsPixmapItem, QPushButton, QGraphicsEllipseItem, QGraphicsPixmapItem, QPushButton,
...@@ -245,6 +248,18 @@ class ImageGraphicsView(QGraphicsView): ...@@ -245,6 +248,18 @@ class ImageGraphicsView(QGraphicsView):
if len(sub_xy) > 1: if len(sub_xy) > 1:
big_xy.extend(sub_xy[1:]) big_xy.extend(sub_xy[1:])
# ---------------------------
# NEW: Smooth the path
# ---------------------------
# big_xy is a list of (x, y). We'll convert to numpy and run savgol_filter
if len(big_xy) >= 7:
arr_xy = np.array(big_xy) # shape (N, 2)
# Apply Savitzky-Golay filter along axis=0
# window_length=7, polyorder=1
smoothed = savgol_filter(arr_xy, window_length=7, polyorder=1, axis=0)
# Convert back to list of (x, y)
big_xy = smoothed.tolist()
# Draw them # Draw them
for (px, py) in big_xy: for (px, py) in big_xy:
path_item = LabeledPointItem(px, py, label="", radius=self.path_radius, path_item = LabeledPointItem(px, py, label="", radius=self.path_radius,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment