Skip to content

Commit

Permalink
MAINT: Use the same tolerance as in the box check for robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
jwboth committed Jun 18, 2024
1 parent 21a9855 commit 9480944
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/darsia/corrections/color/colorcorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def _restrict_to_roi(self, img: np.ndarray) -> np.ndarray:
row_diff = max(row_pixels[1] - row_pixels[0], row_pixels[3] - row_pixels[2])
col_diff = max(col_pixels[1] - col_pixels[0], col_pixels[3] - col_pixels[2])
roi_is_box = row_diff < 0.01 * img.shape[0] and col_diff < 0.01 * img.shape[1]
atol = max(0.01 * img.shape[0], 0.01 * img.shape[1])
if roi_is_box:
# self.roi is more or less a box
roi_slices = (
Expand All @@ -479,16 +480,16 @@ def _restrict_to_roi(self, img: np.ndarray) -> np.ndarray:
box_img = img[roi_slices]
# need to extract a box with the brown sample first - assume the first
# voxel in self.roi is the brown sample
if np.allclose([row_pixels[0], col_pixels[0]], [self.roi[0]]):
if np.allclose([row_pixels[0], col_pixels[0]], [self.roi[0]], atol=atol):
# brown sample is in the upper left corner
return box_img
elif np.allclose([row_pixels[0], col_pixels[3]], [self.roi[0]]):
elif np.allclose([row_pixels[0], col_pixels[3]], [self.roi[0]], atol=atol):
# brown sample is in the upper right corner - rotate 90 degrees clockwise
return np.rot90(box_img, 1)
elif np.allclose([row_pixels[3], col_pixels[3]], [self.roi[0]]):
elif np.allclose([row_pixels[3], col_pixels[3]], [self.roi[0]], atol=atol):
# brown sample is in the lower right corner - rotate 180 degrees
return np.rot90(box_img, -2)
elif np.allclose([row_pixels[3], col_pixels[0]], [self.roi[0]]):
elif np.allclose([row_pixels[3], col_pixels[0]], [self.roi[0]], atol=atol):
# brown sample is in the lower left corner - rotate 90 degrees counterclockwise
return np.rot90(box_img, -1)
else:
Expand Down

0 comments on commit 9480944

Please sign in to comment.