diff --git a/daq/src/aaredaq/daq.py b/daq/src/aaredaq/daq.py index 217c9ba4..cb2496d9 100644 --- a/daq/src/aaredaq/daq.py +++ b/daq/src/aaredaq/daq.py @@ -763,54 +763,14 @@ class AareDAQ: # Subtract the "without feature" image from the "with feature" image diff_image = cv2.absdiff(gray_with_feature, gray_without_feature) - # Threshold the difference to isolate the feature - - def flatfield_correction(raw_image, flat_image, dark_image=None): - """ - Apply flat-field correction to remove uneven illumination - - Args: - raw_image: Your actual image with crystal - flat_image: Image of uniform illumination (no sample) - dark_image: Dark frame (camera with no light), optional - """ - # Convert to float for calculations - raw = raw_image.astype(np.float32) - flat = flat_image.astype(np.float32) - - if dark_image is not None: - dark = dark_image.astype(np.float32) - # Subtract dark frame from both - raw_corrected = raw - dark - flat_corrected = flat - dark - else: - raw_corrected = raw - flat_corrected = flat - - # Avoid division by zero - flat_corrected[flat_corrected == 0] = 1 - - # Apply correction - mean_flat = np.mean(flat_corrected) - corrected = (raw_corrected / flat_corrected) * mean_flat - - # Convert back to original dtype - return np.clip(corrected, 0, 255).astype(raw_image.dtype) - - #_, thresh = cv2.threshold(diff_image, 30, 255, cv2.THRESH_BINARY) thresh_value, thresh = cv2.threshold(diff_image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) - #flatfield_correction_image = flatfield_correction(gray_with_feature, gray_without_feature) - #adapt_thresh = cv2.adaptiveThreshold(gray_with_feature, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, - # 11, 2) - #thresh_value, thresh = cv2.threshold(flatfield_correction_image, 0, 255, - # cv2.THRESH_BINARY + cv2.THRESH_OTSU) print(f'Thresh value: {thresh_value}') if filename is not None: #cv2.imwrite(f"{filename}_curr_image_colour.jpg", curr_image) - #cv2.imwrite(f"{filename}_curr_image.tiff", gray_with_feature) - cv2.imwrite(f"{filename}_diff.tiff", diff_image) - cv2.imwrite(f"{filename}_thresh.tiff", thresh) + cv2.imwrite(f"{filename}_curr_image.jpg", gray_with_feature) + cv2.imwrite(f"{filename}_diff.jpg", diff_image) + cv2.imwrite(f"{filename}_thresh.jpg", thresh) #cv2.imwrite(f"{filename}_adaptive.tiff", adapt_thresh) # # Find contours of the detected feature @@ -834,10 +794,15 @@ class AareDAQ: raise LoopCenteringFailed() geom = self.sample_geometry - - coord = geom.picture_to_smargon( - Coordinate(x=leftmost_point[0], y=leftmost_point[1]) - ) + if iteration == 0: + coord = geom.picture_to_smargon( + Coordinate(x=leftmost_point[0], y=leftmost_point[1]) + ) + else: + #TODO only move x after first iteration + coord = geom.picture_to_smargon( + Coordinate(x=leftmost_point[0], y=leftmost_point[1]) + ) return SmargonCoordinate(sh_mm=coord) def __loop_center_sequence(self, sample_id: int | None = None) -> bool: