Options for capture method, default downsampling of correlations
This commit is contained in:
parent
26163dc97e
commit
132efa8033
2 changed files with 54 additions and 26 deletions
|
|
@ -294,6 +294,7 @@ class AutofocusThing(Thing):
|
|||
capture: CaptureDep,
|
||||
images_dir: str,
|
||||
stack_dir: str,
|
||||
capture_method: str = 'array'
|
||||
) -> None:
|
||||
"""Run a z stack, saving all images to stack_dir and copying the
|
||||
central image to stack_dir"""
|
||||
|
|
@ -307,30 +308,31 @@ class AutofocusThing(Thing):
|
|||
time.sleep(SETTLING_TIME)
|
||||
|
||||
jpeg_path = os.path.join(
|
||||
stack_dir,
|
||||
f"{capture_count}.jpeg",
|
||||
)
|
||||
# The pre-existing capture_jpeg
|
||||
# capture.capture_jpeg(filename=jpeg_path, cam=cam)
|
||||
|
||||
# A new way to get the full array
|
||||
img = capture.capture_jpeg_array()
|
||||
|
||||
stack_dir,
|
||||
f"{capture_count}.jpeg",
|
||||
)
|
||||
metadata = metadata_getter()
|
||||
_save_capture(
|
||||
jpeg_path,
|
||||
img,
|
||||
metadata,
|
||||
logger
|
||||
)
|
||||
|
||||
if capture_method == "blob":
|
||||
capture.capture_jpeg(filename=jpeg_path, cam=cam)
|
||||
elif capture_method == "hires_array":
|
||||
# A new way to get the full array
|
||||
img = capture.capture_jpeg_array()
|
||||
_save_capture(
|
||||
jpeg_path,
|
||||
img,
|
||||
metadata,
|
||||
logger
|
||||
)
|
||||
elif capture_method == "array":
|
||||
# The old capture and save a "main" res image
|
||||
# capture._capture_and_save(
|
||||
# jpeg_path=jpeg_path,
|
||||
# cam=cam,
|
||||
# logger=logger,
|
||||
# metadata_getter=metadata_getter,
|
||||
# )
|
||||
capture._capture_and_save(
|
||||
jpeg_path=jpeg_path,
|
||||
cam=cam,
|
||||
logger=logger,
|
||||
metadata_getter=metadata_getter,
|
||||
)
|
||||
else:
|
||||
raise ValueError('Capture method must be one of "array", "blob" or "hires_array"')
|
||||
|
||||
# If the stack isn't complete yet, move
|
||||
if capture_count + 1 < images_to_capture:
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ class SmartScanThing(Thing):
|
|||
self._scan_images_taken: Optional[int] = None
|
||||
# TODO Scan data is a dict during refactoring, should become a dataclass
|
||||
self._scan_data: Optional[dict] = None
|
||||
self._stitch_resize: Optional[float] = None
|
||||
|
||||
@thing_action
|
||||
def sample_scan(
|
||||
|
|
@ -179,6 +180,7 @@ class SmartScanThing(Thing):
|
|||
self._background_detect = background_detect
|
||||
self._capture_thread = None
|
||||
self._scan_images_taken = 0
|
||||
self._stitch_resize = 1
|
||||
|
||||
# Don't set self._scan_data dictionary. This is done at the start of _run_scan
|
||||
|
||||
|
|
@ -214,6 +216,7 @@ class SmartScanThing(Thing):
|
|||
self._scan_images_taken = None
|
||||
self._scan_data = None
|
||||
self._scan_lock.release()
|
||||
self._stitch_resize = None
|
||||
|
||||
def promote_stitch_files(
|
||||
self,
|
||||
|
|
@ -375,8 +378,24 @@ class SmartScanThing(Thing):
|
|||
|
||||
return (next_point[0], next_point[1], z_estimate)
|
||||
|
||||
# @_scan_running
|
||||
# def _calc_resize_from_test_image(self):
|
||||
# """
|
||||
# Take a test image to set the amount to downsample images for stitching
|
||||
|
||||
# Return the decimal value to scale x and y by when stitching
|
||||
# """
|
||||
|
||||
# #TODO: This needs to match how the capture in the z stack is done
|
||||
# test_jpg = self._cam.capture_jpeg(resolution="full")
|
||||
# test_jpg = test_jpg.content
|
||||
|
||||
# test_image = Image.open(io.BytesIO(test_jpg))
|
||||
# test_image_res = list(test_image.size)
|
||||
# return STITCH_IMAGE_WIDTH / test_image_res[0]
|
||||
|
||||
@_scan_running
|
||||
def _take_test_image_to_calc_displacement(self, overlap):
|
||||
def _calc_displacement_from_test_image(self, overlap):
|
||||
"""
|
||||
Take a test image and use camera stage mapping to calculate x and y displacement
|
||||
|
||||
|
|
@ -421,7 +440,14 @@ class SmartScanThing(Thing):
|
|||
dataclass.
|
||||
"""
|
||||
overlap = self.overlap
|
||||
dx, dy = self._take_test_image_to_calc_displacement(overlap)
|
||||
dx, dy = self._calc_displacement_from_test_image(overlap)
|
||||
# self._stitch_resize = self._calc_resize_from_test_image()
|
||||
self._stitch_resize = 0.25
|
||||
|
||||
self._scan_logger.info(
|
||||
f'Resizing images by {self._stitch_resize}'
|
||||
)
|
||||
|
||||
self._scan_logger.info(
|
||||
f"Based on an overlap of {overlap}, we will make steps of {dx}, {dy}"
|
||||
)
|
||||
|
|
@ -989,7 +1015,7 @@ class SmartScanThing(Thing):
|
|||
"--minimum_overlap",
|
||||
f"{min_overlap}",
|
||||
"--resize",
|
||||
"0.25",
|
||||
f"{self._stitch_resize}",
|
||||
self._ongoing_scan_images_dir,
|
||||
]
|
||||
)
|
||||
|
|
@ -1107,7 +1133,7 @@ class SmartScanThing(Thing):
|
|||
"--minimum_overlap",
|
||||
f"{round(overlap * 0.9, 2)}",
|
||||
"--resize",
|
||||
"0.25",
|
||||
f"{self._stitch_resize}",
|
||||
images_folder,
|
||||
],
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue