Last active
January 3, 2023 08:14
-
-
Save ialhashim/1a1b2fcab3874c126f23cae56bc2e0cf to your computer and use it in GitHub Desktop.
Apply color vibrance adjustments
This file contains hidden or 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
# Copy from https://github.com/bbonik/image_enhancement/blob/f0c286a166443202d592b920b63ee6901a0ee727/source/image_enhancement.py#L1388 | |
import numpy as np | |
from skimage import img_as_float | |
def change_color_saturation( | |
image_color, | |
image_ph_mask=None, | |
sat_degree=1.5,): | |
LOCAL_BOOST = 0.2 | |
THRESHOLD_DARK_TONES = 100 / 255 | |
#TODO: return the same image type | |
image_color = img_as_float(image_color) # [0,1] | |
# define gray scale | |
image_gray = (image_color[:,:,0] + | |
image_color[:,:,1] + | |
image_color[:,:,2]) / 3 | |
image_gray = np.dstack([image_gray] * 3) # grayscale with 3 channels | |
image_delta = image_color - image_gray # deviations from gray | |
# defining local color amplification degree | |
if image_ph_mask is not None: | |
detail_amplification_local = image_ph_mask / THRESHOLD_DARK_TONES | |
detail_amplification_local[detail_amplification_local>1] = 1 | |
detail_amplification_local = ((1 - detail_amplification_local) * | |
LOCAL_BOOST) + 1 # [1, 1.2] | |
detail_amplification_local = np.dstack( | |
[detail_amplification_local] * 3) # 3 channels | |
else: | |
detail_amplification_local = 1 | |
image_new_sat = (image_gray + | |
image_delta * sat_degree * detail_amplification_local) | |
image_new_sat = np.clip( | |
a=image_new_sat, | |
a_min=0, | |
a_max=1, | |
out=image_new_sat | |
) | |
return image_new_sat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment