Spaces:
Sleeping
Sleeping
update interactive pipe version
Browse files- app.py +27 -13
- image_sample_2.jpg +0 -0
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from interactive_pipe import interactive_pipeline, interactive
|
|
|
|
| 2 |
from interactive_pipe.data_objects.curves import SingleCurve, Curve
|
| 3 |
from interactive_pipe.data_objects.image import Image
|
| 4 |
from global_tone_mapping import apply_s_curve_tone_mapping
|
|
@@ -30,7 +31,8 @@ def histogram(img: np.ndarray) -> Curve:
|
|
| 30 |
|
| 31 |
@interactive()
|
| 32 |
def set_tone_mapping_params(
|
| 33 |
-
shadow_boost: float = (0., [-1., 1.]),
|
|
|
|
| 34 |
highlight_boost: float = (0., [-1., 1.]),
|
| 35 |
exposure: float = (0., [-1., 1.]),
|
| 36 |
contrast: float = (0., [-1., 1.]),
|
|
@@ -42,7 +44,9 @@ def set_tone_mapping_params(
|
|
| 42 |
global_params["exposure"] = exposure
|
| 43 |
|
| 44 |
|
| 45 |
-
@interactive(
|
|
|
|
|
|
|
| 46 |
def tone_map(
|
| 47 |
hsv: np.ndarray,
|
| 48 |
apply_tone_curve_on_luma: bool = True,
|
|
@@ -127,27 +131,31 @@ def s_curve_visualization(global_params={}) -> Curve:
|
|
| 127 |
|
| 128 |
|
| 129 |
@interactive(
|
| 130 |
-
input_image=("
|
|
|
|
| 131 |
)
|
| 132 |
def pick_image(
|
| 133 |
default_image: np.ndarray,
|
| 134 |
-
|
|
|
|
| 135 |
global_params={}
|
| 136 |
) -> np.ndarray:
|
| 137 |
-
if input_image == "
|
| 138 |
return default_image
|
| 139 |
-
elif input_image == "
|
| 140 |
-
|
|
|
|
|
|
|
| 141 |
if color_wheel is None:
|
| 142 |
color_wheel = generate_color_wheel(resolution=496)
|
| 143 |
-
global_params["
|
| 144 |
return color_wheel
|
| 145 |
else:
|
| 146 |
return default_image
|
| 147 |
|
| 148 |
|
| 149 |
-
def image_editing_pipeline(sample_image):
|
| 150 |
-
input_image = pick_image(sample_image)
|
| 151 |
set_tone_mapping_params()
|
| 152 |
hsv_in = rgb_to_hsv(input_image)
|
| 153 |
hsv_tc = tone_map(hsv_in)
|
|
@@ -163,9 +171,15 @@ if __name__ == "__main__":
|
|
| 163 |
parser.add_argument("-b", "--backend", type=str,
|
| 164 |
choices=["gradio", "qt", "mpl"], default="gradio")
|
| 165 |
args = parser.parse_args()
|
| 166 |
-
img = Image.load_image("
|
|
|
|
| 167 |
markdown_description = r"# Tone mapping: S-curve" + "\n" \
|
| 168 |
r"$$\text{shadow boost} \in [-1, 1]$$ $$\text{highlight boost} \in [-1, 1]$$ $$\text{contrast} \in [-1, 1]$$ $$\text{exposure} \in [-1, 1]$$" + "\n" \
|
| 169 |
"If Tone curves are applied to RGB colors separately, you'll get serious color shifts. It is much better when tone curve is applied to the luminance channel." + "\n"
|
| 170 |
-
interactive_pipeline(
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from interactive_pipe import interactive_pipeline, interactive
|
| 2 |
+
from interactive_pipe import CircularControl
|
| 3 |
from interactive_pipe.data_objects.curves import SingleCurve, Curve
|
| 4 |
from interactive_pipe.data_objects.image import Image
|
| 5 |
from global_tone_mapping import apply_s_curve_tone_mapping
|
|
|
|
| 31 |
|
| 32 |
@interactive()
|
| 33 |
def set_tone_mapping_params(
|
| 34 |
+
# shadow_boost: float = (0., [-1., 1.]),
|
| 35 |
+
shadow_boost: float = CircularControl(0., [-1., 1.]),
|
| 36 |
highlight_boost: float = (0., [-1., 1.]),
|
| 37 |
exposure: float = (0., [-1., 1.]),
|
| 38 |
contrast: float = (0., [-1., 1.]),
|
|
|
|
| 44 |
global_params["exposure"] = exposure
|
| 45 |
|
| 46 |
|
| 47 |
+
@interactive(
|
| 48 |
+
apply_tone_curve_on_luma=(True,)
|
| 49 |
+
)
|
| 50 |
def tone_map(
|
| 51 |
hsv: np.ndarray,
|
| 52 |
apply_tone_curve_on_luma: bool = True,
|
|
|
|
| 131 |
|
| 132 |
|
| 133 |
@interactive(
|
| 134 |
+
input_image=("sample image", ["sample image",
|
| 135 |
+
"alternative image", "color wheel"]),
|
| 136 |
)
|
| 137 |
def pick_image(
|
| 138 |
default_image: np.ndarray,
|
| 139 |
+
second_image: np.ndarray,
|
| 140 |
+
input_image: str = "sample image",
|
| 141 |
global_params={}
|
| 142 |
) -> np.ndarray:
|
| 143 |
+
if input_image == "sample image":
|
| 144 |
return default_image
|
| 145 |
+
elif input_image == "alternative image":
|
| 146 |
+
return second_image
|
| 147 |
+
elif input_image == "color wheel":
|
| 148 |
+
color_wheel = global_params.get("color wheel", None)
|
| 149 |
if color_wheel is None:
|
| 150 |
color_wheel = generate_color_wheel(resolution=496)
|
| 151 |
+
global_params["color wheel"] = color_wheel
|
| 152 |
return color_wheel
|
| 153 |
else:
|
| 154 |
return default_image
|
| 155 |
|
| 156 |
|
| 157 |
+
def image_editing_pipeline(sample_image, second_image):
|
| 158 |
+
input_image = pick_image(sample_image, second_image)
|
| 159 |
set_tone_mapping_params()
|
| 160 |
hsv_in = rgb_to_hsv(input_image)
|
| 161 |
hsv_tc = tone_map(hsv_in)
|
|
|
|
| 171 |
parser.add_argument("-b", "--backend", type=str,
|
| 172 |
choices=["gradio", "qt", "mpl"], default="gradio")
|
| 173 |
args = parser.parse_args()
|
| 174 |
+
img = Image.load_image("image_sample_2.jpg")
|
| 175 |
+
img2 = Image.load_image("image_sample.jpg")
|
| 176 |
markdown_description = r"# Tone mapping: S-curve" + "\n" \
|
| 177 |
r"$$\text{shadow boost} \in [-1, 1]$$ $$\text{highlight boost} \in [-1, 1]$$ $$\text{contrast} \in [-1, 1]$$ $$\text{exposure} \in [-1, 1]$$" + "\n" \
|
| 178 |
"If Tone curves are applied to RGB colors separately, you'll get serious color shifts. It is much better when tone curve is applied to the luminance channel." + "\n"
|
| 179 |
+
interactive_pipeline(
|
| 180 |
+
gui=args.backend,
|
| 181 |
+
markdown_description=markdown_description,
|
| 182 |
+
sliders_layout=["compact", "group",
|
| 183 |
+
"vertical", "collapsible", "smart"][2],
|
| 184 |
+
sliders_per_row_layout=1
|
| 185 |
+
)(image_editing_pipeline)(img, img2)
|
image_sample_2.jpg
ADDED
|
requirements.txt
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
interactive-pipe
|
|
|
|
| 1 |
+
interactive-pipe>=0.7.3
|