Skip to content

Commit

Permalink
BUG: Need to make sure that the brown sample is chosen first - rotate…
Browse files Browse the repository at this point in the history
… box
  • Loading branch information
jwboth committed Jun 18, 2024
1 parent 66111c1 commit 21a9855
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/darsia/corrections/color/colorcorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,24 @@ def _restrict_to_roi(self, img: np.ndarray) -> np.ndarray:
slice(row_pixels[0], row_pixels[3]),
slice(col_pixels[0], col_pixels[3]),
)
return img[roi_slices]
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]]):
# brown sample is in the upper left corner
return box_img
elif np.allclose([row_pixels[0], col_pixels[3]], [self.roi[0]]):
# 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]]):
# 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]]):
# brown sample is in the lower left corner - rotate 90 degrees counterclockwise
return np.rot90(box_img, -1)
else:
raise ValueError("The brown sample is not in the corner of the ROI.")

else:
# Use width and height (in cm - irrelevant) as provided by the manufacturer Xrite.
return darsia.extract_quadrilateral_ROI(
Expand Down

0 comments on commit 21a9855

Please sign in to comment.