-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions for contrast enhancement
- Loading branch information
1 parent
b8bfe12
commit 95e7a8d
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |