Skip to content

Commit

Permalink
Add working derotation of incremental images
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraporta committed Oct 27, 2023
1 parent 8ca170c commit 66d9a05
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions derotation/analysis/derotate_incremental_rotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.small_rotations = 10
self.number_of_rotations = len(self.rot_deg // self.small_rotations)
self.number_of_rotations = self.rot_deg // self.small_rotations

def __call__(self):
super().process_analog_signals()
# self.check_number_of_frame_angles()
rotated_images = self.roatate_by_frame()
masked = self.add_circle_mask(rotated_images)
self.save(masked)
self.save_csv_with_derotation_data()

def is_number_of_ticks_correct(self) -> bool:
self.expected_tiks_per_rotation = (
Expand Down Expand Up @@ -83,6 +85,7 @@ def get_interpolated_angles(self) -> np.ndarray:
return interpolated_angles * -1

def roatate_by_frame(self):
logging.info("Starting derotation by frame...")
min_value_img = np.min(self.image_stack)
new_rotated_image_stack = (
np.ones_like(self.image_stack) * min_value_img
Expand All @@ -91,17 +94,32 @@ def roatate_by_frame(self):
for idx, frame in tqdm(
enumerate(self.image_stack), total=self.num_frames
):
new_rotated_image_stack[idx] = rotate(
rotated_img = rotate(
frame,
self.rot_deg_frame[idx],
reshape=False,
order=0,
mode="constant",
)
rotated_img = np.where(
rotated_img == 0, min_value_img, rotated_img
)

new_rotated_image_stack[idx] = rotated_img

logging.info("Finished rotating the image stack")

return new_rotated_image_stack

def check_number_of_frame_angles(self):
if len(self.rot_deg_frame) != self.num_frames:
raise ValueError(
"Number of rotation angles by frame is not equal to the "
+ "number of frames in the image stack.\n"
+ f"Number of angles: {len(self.rot_deg_frame)}\n"
+ f"Number of frames: {self.num_frames}"
)

def plot_rotation_angles(self):
"""Plots example rotation angles by line and frame for each speed.
This plot will be saved in the debug_plots folder.
Expand Down

0 comments on commit 66d9a05

Please sign in to comment.