diff --git a/GUI_draft.py b/GUI_draft.py index a28f30f9c0d72dbf07d3483ddf3f8e934156ab95..899433412968c4197265ac39af4045246ccaa739 100644 --- a/GUI_draft.py +++ b/GUI_draft.py @@ -2,6 +2,9 @@ import sys import math import numpy as np +# NEW IMPORT +from scipy.signal import savgol_filter + from PyQt5.QtWidgets import ( QApplication, QMainWindow, QGraphicsView, QGraphicsScene, QGraphicsEllipseItem, QGraphicsPixmapItem, QPushButton, @@ -245,6 +248,18 @@ class ImageGraphicsView(QGraphicsView): if len(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 for (px, py) in big_xy: path_item = LabeledPointItem(px, py, label="", radius=self.path_radius,