Skip to content

Commit

Permalink
Add functions for contrast enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraporta committed Jul 26, 2024
1 parent b8bfe12 commit 95e7a8d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions derotation/preprocessing/contrast_enhancement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pathlib import Path

import numpy as np
import tifffile as tf
from skimage.exposure import rescale_intensity


def whole_video_contrast_enhancment(
tiff_path: Path, saturated_percentage: float
):
tiff = tf.imread(tiff_path)
v_min, v_max = np.percentile(
tiff, (saturated_percentage, 100 - saturated_percentage)
)

CE_tiff_path = np.zeros_like(tiff)
for i, frame in enumerate(tiff):
CE_tiff_path[i] = rescale_intensity(frame, in_range=(v_min, v_max))

return CE_tiff_path


def frame_by_frame_contrast_enhancement(
tiff_path: Path, saturated_percentage: float
):
tiff = tf.imread(tiff_path)

CE_tiff_path = np.zeros_like(tiff)
for i, frame in enumerate(tiff):
v_min, v_max = np.percentile(
frame, (saturated_percentage, 100 - saturated_percentage)
)
CE_tiff_path[i] = rescale_intensity(frame, in_range=(v_min, v_max))

return CE_tiff_path

0 comments on commit 95e7a8d

Please sign in to comment.