Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use contrast enhancement to improve registration #23

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions derotation/postprocessing/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
Loading