Spaces:
Sleeping
Sleeping
add vibrance
Browse files
app.py
CHANGED
|
@@ -43,8 +43,8 @@ def set_tone_mapping_params(
|
|
| 43 |
|
| 44 |
|
| 45 |
@interactive(apply_tone_curve_on_luma=(True,))
|
| 46 |
-
def
|
| 47 |
-
|
| 48 |
apply_tone_curve_on_luma: bool = True,
|
| 49 |
global_params={}
|
| 50 |
) -> np.ndarray:
|
|
@@ -53,14 +53,15 @@ def s_curve_tone_mapping(
|
|
| 53 |
contrast = global_params.get("contrast", 0.)
|
| 54 |
exposure = global_params.get("exposure", 0.)
|
| 55 |
if not apply_tone_curve_on_luma:
|
| 56 |
-
return
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
| 62 |
)
|
| 63 |
-
hsv = rgb_to_hsv(img)
|
| 64 |
luma_tone_mapped = apply_s_curve_tone_mapping(
|
| 65 |
hsv[..., -1],
|
| 66 |
shadow_boost,
|
|
@@ -69,7 +70,26 @@ def s_curve_tone_mapping(
|
|
| 69 |
exposure
|
| 70 |
)
|
| 71 |
hsv[..., -1] = luma_tone_mapped
|
| 72 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
def s_curve_visualization(global_params={}) -> Curve:
|
|
@@ -115,7 +135,10 @@ def pick_image(
|
|
| 115 |
def image_editing_pipeline(sample_image):
|
| 116 |
input_image = pick_image(sample_image)
|
| 117 |
set_tone_mapping_params()
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
| 119 |
tone_curve = s_curve_visualization()
|
| 120 |
histogram_curve = histogram(tc_image)
|
| 121 |
return tc_image, histogram_curve, tone_curve
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
@interactive(apply_tone_curve_on_luma=(True,))
|
| 46 |
+
def tone_map(
|
| 47 |
+
hsv: np.ndarray,
|
| 48 |
apply_tone_curve_on_luma: bool = True,
|
| 49 |
global_params={}
|
| 50 |
) -> np.ndarray:
|
|
|
|
| 53 |
contrast = global_params.get("contrast", 0.)
|
| 54 |
exposure = global_params.get("exposure", 0.)
|
| 55 |
if not apply_tone_curve_on_luma:
|
| 56 |
+
return rgb_to_hsv(
|
| 57 |
+
apply_s_curve_tone_mapping(
|
| 58 |
+
hsv_to_rgb(hsv),
|
| 59 |
+
shadow_boost,
|
| 60 |
+
highlight_boost,
|
| 61 |
+
contrast,
|
| 62 |
+
exposure
|
| 63 |
+
)
|
| 64 |
)
|
|
|
|
| 65 |
luma_tone_mapped = apply_s_curve_tone_mapping(
|
| 66 |
hsv[..., -1],
|
| 67 |
shadow_boost,
|
|
|
|
| 70 |
exposure
|
| 71 |
)
|
| 72 |
hsv[..., -1] = luma_tone_mapped
|
| 73 |
+
return hsv
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
@interactive(vibrance=(0, [0, 100]))
|
| 77 |
+
def modify_vibrance(hsv_in, vibrance: float = 0.):
|
| 78 |
+
gain_luma = np.interp(hsv_in[..., 2], [0., 0.5, 1.], [0., 0., 1.])
|
| 79 |
+
gain_sat = np.interp(hsv_in[..., 1], [0., 0.5, 1.], [0., 0., 1.])**2
|
| 80 |
+
red_thresh = 30.
|
| 81 |
+
pink_thresh = 8.
|
| 82 |
+
overlap = 10.
|
| 83 |
+
|
| 84 |
+
gain_hue = np.interp(
|
| 85 |
+
hsv_in[..., 0],
|
| 86 |
+
[0., red_thresh, red_thresh+overlap,
|
| 87 |
+
360-pink_thresh-overlap, 360-pink_thresh, 360],
|
| 88 |
+
[0., 0., 1., 1., 0., 0.]
|
| 89 |
+
)**2
|
| 90 |
+
gain = 1. + gain_luma * gain_sat * gain_hue*(vibrance / 100)
|
| 91 |
+
hsv_in[..., 1] = np.clip(gain*hsv_in[..., 1], 0, 1)
|
| 92 |
+
return hsv_in
|
| 93 |
|
| 94 |
|
| 95 |
def s_curve_visualization(global_params={}) -> Curve:
|
|
|
|
| 135 |
def image_editing_pipeline(sample_image):
|
| 136 |
input_image = pick_image(sample_image)
|
| 137 |
set_tone_mapping_params()
|
| 138 |
+
hsv_in = rgb_to_hsv(input_image)
|
| 139 |
+
hsv_tc = tone_map(hsv_in)
|
| 140 |
+
hsv_out = modify_vibrance(hsv_tc)
|
| 141 |
+
tc_image = hsv_to_rgb(hsv_out)
|
| 142 |
tone_curve = s_curve_visualization()
|
| 143 |
histogram_curve = histogram(tc_image)
|
| 144 |
return tc_image, histogram_curve, tone_curve
|