Skip to content

Commit

Permalink
Remove contrast enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraporta committed Jul 4, 2024
1 parent 5a9d43e commit 02e4a95
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
84 changes: 42 additions & 42 deletions derotation/analysis/full_rotation_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __call__(self):
- adding a circular mask to the rotated image stack
- saving the masked image stack
"""
self.contrast_enhancement()
# self.contrast_enhancement()
self.process_analog_signals()
rotated_images = self.rotate_frames_line_by_line()
masked = self.add_circle_mask(rotated_images, self.mask_diameter)
Expand Down Expand Up @@ -172,44 +172,44 @@ def load_data(self):
logging.info(f"Dataset {self.filename_raw} loaded")
logging.info(f"Filename: {self.filename}")

def contrast_enhancement(self):
"""Applies contrast enhancement to the image stack.
It is useful to visualize the image stack before derotation.
"""
logging.info("Applying contrast enhancement...")

self.image_stack = np.array(
[
self.contrast_enhancement_single_image(
img, self.config["contrast_enhancement"]
)
for img in self.image_stack
]
)

@staticmethod
def contrast_enhancement_single_image(
img: np.ndarray, saturated_percentage=0.35
) -> np.ndarray:
"""Applies contrast enhancement to a single image.
It is useful to visualize the image stack before derotation.
Parameters
----------
img : np.ndarray
The image to enhance.
saturated_percentage : float, optional
The percentage of saturated pixels, by default 0.35
Returns
-------
np.ndarray
The enhanced image.
"""
v_min, v_max = np.percentile(
img, (saturated_percentage, 100 - saturated_percentage)
)
return rescale_intensity(img, in_range=(v_min, v_max))
# def contrast_enhancement(self):
# """Applies contrast enhancement to the image stack.
# It is useful to visualize the image stack before derotation.
# """
# logging.info("Applying contrast enhancement...")

# self.image_stack = np.array(
# [
# self.contrast_enhancement_single_image(
# img, self.config["contrast_enhancement"]
# )
# for img in self.image_stack
# ]
# )

# @staticmethod
# def contrast_enhancement_single_image(
# img: np.ndarray, saturated_percentage=0.35
# ) -> np.ndarray:
# """Applies contrast enhancement to a single image.
# It is useful to visualize the image stack before derotation.

# Parameters
# ----------
# img : np.ndarray
# The image to enhance.
# saturated_percentage : float, optional
# The percentage of saturated pixels, by default 0.35

# Returns
# -------
# np.ndarray
# The enhanced image.
# """
# v_min, v_max = np.percentile(
# img, (saturated_percentage, 100 - saturated_percentage)
# )
# return rescale_intensity(img, in_range=(v_min, v_max))

def process_analog_signals(self):
"""From the analog signals (frame clock, line clock, full rotation,
Expand Down Expand Up @@ -470,8 +470,8 @@ def check_number_of_rotations(self):
raise ValueError(
"Start and end of rotations have different lengths"
)
# if self.rot_blocks_idx["start"].shape[0] != self.number_of_rotations:
# raise ValueError("Number of rotations is not as expected")
if self.rot_blocks_idx["start"].shape[0] != self.number_of_rotations:
raise ValueError("Number of rotations is not as expected")

logging.info("Number of rotations is as expected")

Expand Down Expand Up @@ -612,7 +612,7 @@ def remove_artifacts_from_interpolated_angles(self):
rotation_end = np.where(np.diff(thresholded) < 0)[0]

assert len(rotation_start) == len(rotation_end)
# assert len(rotation_start) == self.number_of_rotations
assert len(rotation_start) == self.number_of_rotations

for i, (start, end) in enumerate(
zip(rotation_start[1:], rotation_end[:-1])
Expand Down
1 change: 1 addition & 0 deletions derotation/config/full_rotation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ channel_names: [
"PI_rotticks",
]


rotation_increment: 0.2
adjust_increment: True
rot_deg: 360
Expand Down

0 comments on commit 02e4a95

Please sign in to comment.