From b8ddab1ed8ad214c2850a410b12731d126299824 Mon Sep 17 00:00:00 2001 From: jaknapper Date: Mon, 14 Apr 2025 17:34:11 +0100 Subject: [PATCH 1/3] Remove correlation only stitching, now covered by preview stitch --- .../things/smart_scan.py | 43 ++----------------- 1 file changed, 4 insertions(+), 39 deletions(-) diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index f19e41a6..4e067ace 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -132,8 +132,6 @@ class SmartScanThing(Thing): self._stitching_script = path_to_openflexure_stitch self._preview_stitch_popen = None self._preview_stitch_popen_lock = threading.Lock() - self._correlate_popen = None - self._correlate_popen_lock = threading.Lock() self._scan_lock = threading.Lock() # Variables set by the scan @@ -472,10 +470,7 @@ class SmartScanThing(Thing): """ if self._scan_images_taken > 3: if not self._preview_stitch_running(): - self._preview_stitch_start() - if self._scan_data["stitch_automatically"]: - if not self._correlate_running(): - self._correlate_start(overlap=self._scan_data["overlap"]) + self._preview_stitch_start(overlap=self._scan_data["overlap"]) @_scan_running def _run_scan(self): @@ -708,7 +703,6 @@ class SmartScanThing(Thing): self._scan_logger.info("Waiting for background processes to finish...") self._preview_stitch_wait() - self._correlate_wait() try: if self._scan_data["stitch_automatically"]: self._scan_logger.info("Stitching final image (may take some time)...") @@ -985,7 +979,7 @@ class SmartScanThing(Thing): raise HTTPException(404, "File not found") @_scan_running - def _preview_stitch_start(self) -> None: + def _preview_stitch_start(self, overlap: float = 0.1) -> None: """Start stitching a preview of the scan in a background subprocess @@ -1003,6 +997,8 @@ class SmartScanThing(Thing): self._stitching_script, "--stitching_mode", "only_stage_stitch", + "--minimum_overlap", + f"{round(overlap * 0.9, 2)}", self._ongoing_scan_images_dir, ] ) @@ -1023,38 +1019,7 @@ class SmartScanThing(Thing): with self._preview_stitch_popen_lock: self._preview_stitch_popen.wait() - @_scan_running - def _correlate_start(self, overlap: float = 0.1) -> None: - """Start stitching a preview of the scan in a subprocess""" - if self._correlate_running(): - raise RuntimeError("Only one subprocess is allowed at a time") - with self._correlate_popen_lock: - self._correlate_popen = Popen( - [ - self._stitching_script, - "--stitching_mode", - "only_correlate", - "--minimum_overlap", - f"{round(overlap * 0.9, 2)}", - self._ongoing_scan_images_dir, - ] - ) - @_scan_running - def _correlate_running(self) -> bool: - """Whether there is a preview stitch running in a subprocess""" - with self._correlate_popen_lock: - if self._correlate_popen is None: - return False - if self._correlate_popen.poll() is None: - return True - return False - - @_scan_running - def _correlate_wait(self): - if self._correlate_running(): - with self._correlate_popen_lock: - self._correlate_popen.wait() def run_subprocess( self, From fbbb3decdc0c5cabd055e093c4868f591f6a369b Mon Sep 17 00:00:00 2001 From: jaknapper Date: Tue, 15 Apr 2025 16:50:43 +0100 Subject: [PATCH 2/3] Ruff formatting --- src/openflexure_microscope_server/things/smart_scan.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 4e067ace..81f2158b 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -1019,8 +1019,6 @@ class SmartScanThing(Thing): with self._preview_stitch_popen_lock: self._preview_stitch_popen.wait() - - def run_subprocess( self, logger: InvocationLogger, From a1be3e518f88098c12c0d4b78449b5bb32e021d9 Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Thu, 1 May 2025 14:14:34 +0000 Subject: [PATCH 3/3] Apply 2 suggestion(s) to 1 file(s) Co-authored-by: Julian Stirling --- src/openflexure_microscope_server/things/smart_scan.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 81f2158b..e2416c03 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -979,7 +979,7 @@ class SmartScanThing(Thing): raise HTTPException(404, "File not found") @_scan_running - def _preview_stitch_start(self, overlap: float = 0.1) -> None: + def _preview_stitch_start(self, overlap: float) -> None: """Start stitching a preview of the scan in a background subprocess @@ -989,6 +989,9 @@ class SmartScanThing(Thing): - self._preview_stitch_popen_lock is a lock aquired while interacting with Popen """ + # Set minimum overlap to 90% of the scan overlap to catch only images directly adjacent, + # not images with overlapping corners. + min_overlap = round(overlap * 0.9, 2) if self._preview_stitch_running(): raise RuntimeError("Only one subprocess is allowed at a time") with self._preview_stitch_popen_lock: @@ -998,7 +1001,7 @@ class SmartScanThing(Thing): "--stitching_mode", "only_stage_stitch", "--minimum_overlap", - f"{round(overlap * 0.9, 2)}", + f"{min_overlap}", self._ongoing_scan_images_dir, ] )