Run stitching thing with appropriate overlap setting

This commit is contained in:
Joe Knapper 2024-01-13 13:38:39 +00:00
parent d369105111
commit d1908eb29a

View file

@ -553,7 +553,7 @@ class SmartScanThing(Thing):
if not self.preview_stitch_running(): if not self.preview_stitch_running():
self.preview_stitch_start(images_folder) self.preview_stitch_start(images_folder)
if not self.correlate_running(): if not self.correlate_running():
self.correlate_start(images_folder) self.correlate_start(images_folder, overlap=overlap)
# add the current position to the list of all positions visited # add the current position to the list of all positions visited
true_path.append(loc) true_path.append(loc)
@ -602,7 +602,7 @@ class SmartScanThing(Thing):
logger.info("Stitching final image (may take some time)...") logger.info("Stitching final image (may take some time)...")
try: try:
if scan_folder: if scan_folder:
self.stitch_scan(logger, os.path.basename(scan_folder)) self.stitch_scan(logger, os.path.basename(scan_folder), overlap=overlap)
except SubprocessError as e: except SubprocessError as e:
logger.exception(f"Stitching failed: {e}") logger.exception(f"Stitching failed: {e}")
logger.info("Creating zip archive of images (may take some time)...") logger.info("Creating zip archive of images (may take some time)...")
@ -804,13 +804,13 @@ class SmartScanThing(Thing):
self._preview_stitch_popen.wait() self._preview_stitch_popen.wait()
_correlate_popen = None _correlate_popen = None
def correlate_start(self, images_folder: str) -> None: def correlate_start(self, images_folder: str, overlap: float = 0.1) -> None:
"""Start stitching a preview of the scan in a subprocess""" """Start stitching a preview of the scan in a subprocess"""
if self.correlate_running(): if self.correlate_running():
raise RuntimeError("Only one subprocess is allowed at a time") raise RuntimeError("Only one subprocess is allowed at a time")
with self._correlate_popen_lock: with self._correlate_popen_lock:
self._correlate_popen = Popen( self._correlate_popen = Popen(
[self._script, "--stitching_mode", "only_correlate", images_folder] [self._script, "--stitching_mode", "only_correlate", "--minimum_overlap", f"{overlap*0.9}", images_folder]
) )
def correlate_running(self) -> bool: def correlate_running(self) -> bool:
@ -840,8 +840,8 @@ class SmartScanThing(Thing):
return output return output
@thing_action @thing_action
def stitch_scan(self, logger: InvocationLogger, scan_name: Optional[str]=None, downsample: float=1.0) -> None: def stitch_scan(self, logger: InvocationLogger, scan_name: Optional[str]=None, overlap: float = 0.1) -> None:
"""Generate a stitched image based on stage position metadata""" """Generate a stitched image based on stage position metadata"""
images_folder = self.images_folder(scan_name=scan_name) images_folder = self.images_folder(scan_name=scan_name)
self.run_subprocess(logger, [self._script, "--stitching_mode", "all", images_folder]) self.run_subprocess(logger, [self._script, "--stitching_mode", "all", "--minimum_overlap", f"{overlap*0.9}", images_folder])