Upload segmentation_editor.py
Browse files- segmentation_editor.py +17 -3
segmentation_editor.py
CHANGED
|
@@ -6,15 +6,18 @@ import glob
|
|
| 6 |
import json
|
| 7 |
|
| 8 |
class SegmentationEditor:
|
| 9 |
-
def __init__(self, input_dir, output_dir="edited_segmented_images"):
|
| 10 |
self.input_dir = input_dir
|
| 11 |
self.output_dir = output_dir
|
| 12 |
self.image_files = sorted(glob.glob(os.path.join(input_dir, "*.png")))
|
| 13 |
-
self.current_index =
|
| 14 |
|
| 15 |
if not self.image_files:
|
| 16 |
raise ValueError(f"No PNG files found in {input_dir}")
|
| 17 |
|
|
|
|
|
|
|
|
|
|
| 18 |
# Store cut lines for each image
|
| 19 |
self.cut_lines = {} # image_path -> list of y coordinates
|
| 20 |
self.current_image = None
|
|
@@ -30,6 +33,7 @@ class SegmentationEditor:
|
|
| 30 |
self.window_name = "Segmentation Editor - Left/Right: Navigate | Left Click: Add | Right Click: Delete | S: Save | ESC: Exit"
|
| 31 |
|
| 32 |
print(f"Loaded {len(self.image_files)} images")
|
|
|
|
| 33 |
print("Controls:")
|
| 34 |
print(" LEFT/RIGHT ARROW: Navigate between images (auto-saves current)")
|
| 35 |
print(" LEFT CLICK: Add cut line at cursor position")
|
|
@@ -318,8 +322,18 @@ def main():
|
|
| 318 |
print(f"Error: Input directory {input_dir} not found")
|
| 319 |
return
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
try:
|
| 322 |
-
editor = SegmentationEditor(input_dir, output_dir)
|
| 323 |
editor.run()
|
| 324 |
except Exception as e:
|
| 325 |
print(f"Error: {e}")
|
|
|
|
| 6 |
import json
|
| 7 |
|
| 8 |
class SegmentationEditor:
|
| 9 |
+
def __init__(self, input_dir, output_dir="edited_segmented_images", start_index=0):
|
| 10 |
self.input_dir = input_dir
|
| 11 |
self.output_dir = output_dir
|
| 12 |
self.image_files = sorted(glob.glob(os.path.join(input_dir, "*.png")))
|
| 13 |
+
self.current_index = start_index
|
| 14 |
|
| 15 |
if not self.image_files:
|
| 16 |
raise ValueError(f"No PNG files found in {input_dir}")
|
| 17 |
|
| 18 |
+
if start_index >= len(self.image_files):
|
| 19 |
+
raise ValueError(f"Starting index {start_index+1} is greater than total images {len(self.image_files)}")
|
| 20 |
+
|
| 21 |
# Store cut lines for each image
|
| 22 |
self.cut_lines = {} # image_path -> list of y coordinates
|
| 23 |
self.current_image = None
|
|
|
|
| 33 |
self.window_name = "Segmentation Editor - Left/Right: Navigate | Left Click: Add | Right Click: Delete | S: Save | ESC: Exit"
|
| 34 |
|
| 35 |
print(f"Loaded {len(self.image_files)} images")
|
| 36 |
+
print(f"Starting from image {start_index+1}: {Path(self.image_files[start_index]).name}")
|
| 37 |
print("Controls:")
|
| 38 |
print(" LEFT/RIGHT ARROW: Navigate between images (auto-saves current)")
|
| 39 |
print(" LEFT CLICK: Add cut line at cursor position")
|
|
|
|
| 322 |
print(f"Error: Input directory {input_dir} not found")
|
| 323 |
return
|
| 324 |
|
| 325 |
+
# Get starting image number from user
|
| 326 |
+
try:
|
| 327 |
+
start_num = int(input("Enter starting image number (1-based): "))
|
| 328 |
+
if start_num < 1:
|
| 329 |
+
print("Error: Image number must be at least 1")
|
| 330 |
+
return
|
| 331 |
+
except ValueError:
|
| 332 |
+
print("Error: Please enter a valid number")
|
| 333 |
+
return
|
| 334 |
+
|
| 335 |
try:
|
| 336 |
+
editor = SegmentationEditor(input_dir, output_dir, start_index=start_num-1)
|
| 337 |
editor.run()
|
| 338 |
except Exception as e:
|
| 339 |
print(f"Error: {e}")
|