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

Now exports path as csv with correct labelling of points

parent b50c1a85
No related branches found
No related tags found
No related merge requests found
import sys
import math
import csv # <-- Added
import numpy as np
# For smoothing the path
......@@ -778,8 +779,6 @@ class AdvancedSettingsWidget(QWidget):
Shows toggle rainbow, circle editor, line smoothing slider, contrast slider,
plus two image previews (contrasted-blurred and cost).
The images should maintain aspect ratio upon resize.
Now displays the images stacked vertically with labels above them.
"""
def __init__(self, main_window, parent=None):
super().__init__(parent)
......@@ -1114,21 +1113,55 @@ class MainWindow(QMainWindow):
return gray
def export_path(self):
"""
Exports the path as a CSV in the format: x, y, TYPE,
ensuring that each anchor influences exactly one path point.
"""
full_xy = self.image_view.get_full_path_xy()
if not full_xy:
print("No path to export.")
return
# We'll consider each anchor point as "USER-PLACED".
# But unlike a distance-threshold approach, we assign each anchor
# to exactly one closest path point.
anchor_points = self.image_view.anchor_points
# For each anchor, find the index of the closest path point
user_placed_indices = set()
for ax, ay in anchor_points:
min_dist = float('inf')
closest_idx = None
for i, (px, py) in enumerate(full_xy):
dist = math.hypot(px - ax, py - ay)
if dist < min_dist:
min_dist = dist
closest_idx = i
if closest_idx is not None:
user_placed_indices.add(closest_idx)
# Ask user for the CSV filename
options = QFileDialog.Options()
file_path, _ = QFileDialog.getSaveFileName(
self, "Export Path", "",
"NumPy Files (*.npy);;All Files (*)",
"CSV Files (*.csv);;All Files (*)",
options=options
)
if file_path:
arr = np.array(full_xy)
np.save(file_path, arr)
print(f"Exported path with {len(arr)} points to {file_path}")
if not file_path:
return
import csv
with open(file_path, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["x", "y", "TYPE"])
for i, (x, y) in enumerate(full_xy):
ptype = "USER-PLACED" if i in user_placed_indices else "PATH"
writer.writerow([x, y, ptype])
print(f"Exported path with {len(full_xy)} points to {file_path}")
def clear_points(self):
self.image_view.clear_guide_points()
......
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