Spaces:
Running
Running
update html
Browse files- app.py +17 -10
- demo_header.html +6 -1
- demo_tools.html +7 -1
app.py
CHANGED
@@ -8,11 +8,12 @@ from skimage.exposure import match_histograms
|
|
8 |
from gradio_utils import save_image
|
9 |
from color_utils import simple_white_balance,apply_tone_curve,curve_midtones,create_left_half_mask,create_top_half_mask,create_compare_image ,mirror
|
10 |
|
11 |
-
def color_match(base_image,cropped_image):
|
12 |
-
reference = np.array(base_image)
|
13 |
-
target =np.array(cropped_image)
|
14 |
matched = match_histograms(target, reference,channel_axis=-1)
|
15 |
-
|
|
|
16 |
|
17 |
|
18 |
|
@@ -51,7 +52,8 @@ def create_enhanced_image(reference_image,brightness=1.0,color=1.0,contrast=1.0,
|
|
51 |
|
52 |
|
53 |
|
54 |
-
def process_images(reference_image_dict,target_image_dict,mirror_target=False,middle_tone_value=0.75):
|
|
|
55 |
if reference_image_dict == None:
|
56 |
raise gr.Error("Need reference_image")
|
57 |
|
@@ -75,18 +77,21 @@ def process_images(reference_image_dict,target_image_dict,mirror_target=False,mi
|
|
75 |
left_mask = create_left_half_mask(reference_image)
|
76 |
top_mask = create_top_half_mask(reference_image)
|
77 |
|
78 |
-
color_matched = color_match(reference_image,target_image)
|
79 |
color_matched_resized = color_matched.resize(reference_image.size)
|
80 |
matched_path = save_image(color_matched.convert("RGB"))
|
81 |
images.append((matched_path,"color matched"))
|
82 |
-
|
|
|
83 |
reference_mix_left,reference_mix_right = create_compare_image(reference_image,color_matched_resized,left_mask)
|
84 |
images.append((save_image(reference_mix_left.convert("RGB"),extension="webp"),"mixed_left"))
|
85 |
images.append((save_image(reference_mix_right.convert("RGB"),extension="webp"),"mixed_right"))
|
|
|
86 |
|
87 |
reference_mix_top,reference_mix_bottom = create_compare_image(reference_image,color_matched_resized,top_mask)
|
88 |
images.append((save_image(reference_mix_top.convert("RGB"),extension="webp"),"mixed_top"))
|
89 |
images.append((save_image(reference_mix_bottom.convert("RGB"),extension="webp"),"mixed_bottom"))
|
|
|
90 |
|
91 |
color_matched_tone = apply_tone_curve(color_matched.convert("RGB"),curve_midtones,middle_tone_value)
|
92 |
color_matched_tone_resized = color_matched_tone.resize(reference_image.size)
|
@@ -95,11 +100,12 @@ def process_images(reference_image_dict,target_image_dict,mirror_target=False,mi
|
|
95 |
reference_mix_left,reference_mix_right = create_compare_image(reference_image,color_matched_tone_resized,left_mask)
|
96 |
images.append((save_image(reference_mix_left.convert("RGB"),extension="webp"),"mixed_left"))
|
97 |
images.append((save_image(reference_mix_right.convert("RGB"),extension="webp"),"mixed_right"))
|
98 |
-
|
|
|
99 |
reference_mix_top,reference_mix_bottom = create_compare_image(reference_image,color_matched_tone_resized,top_mask)
|
100 |
images.append((save_image(reference_mix_top.convert("RGB"),extension="webp"),"mixed_top"))
|
101 |
images.append((save_image(reference_mix_bottom.convert("RGB"),extension="webp"),"mixed_bottom"))
|
102 |
-
|
103 |
|
104 |
return images
|
105 |
|
@@ -188,6 +194,7 @@ with gr.Blocks(css=css, elem_id="demo-container") as demo:
|
|
188 |
maximum=2.0,
|
189 |
step=0.01,
|
190 |
value=0.75)
|
|
|
191 |
|
192 |
with gr.Column():
|
193 |
image_out = gr.Gallery(height=800,label="Output", elem_id="output-img",format="webp", preview=True)
|
@@ -199,7 +206,7 @@ with gr.Blocks(css=css, elem_id="demo-container") as demo:
|
|
199 |
|
200 |
gr.on(
|
201 |
[btn1.click],
|
202 |
-
fn=process_images, inputs=[reference_image,target_image,mirror_target,middle_tone_value], outputs =[image_out], api_name='infer'
|
203 |
)
|
204 |
gr.Examples(
|
205 |
examples =[
|
|
|
8 |
from gradio_utils import save_image
|
9 |
from color_utils import simple_white_balance,apply_tone_curve,curve_midtones,create_left_half_mask,create_top_half_mask,create_compare_image ,mirror
|
10 |
|
11 |
+
def color_match(base_image,cropped_image,color_match_format="RGB"):
|
12 |
+
reference = np.array(base_image.convert(color_match_format))
|
13 |
+
target =np.array(cropped_image.convert(color_match_format))
|
14 |
matched = match_histograms(target, reference,channel_axis=-1)
|
15 |
+
|
16 |
+
return Image.fromarray(matched,mode=color_match_format)
|
17 |
|
18 |
|
19 |
|
|
|
52 |
|
53 |
|
54 |
|
55 |
+
def process_images(reference_image_dict,target_image_dict,mirror_target=False,middle_tone_value=0.75,color_match_format="RGB",progress=gr.Progress(track_tqdm=True)):
|
56 |
+
progress(0, desc="Start color matching")
|
57 |
if reference_image_dict == None:
|
58 |
raise gr.Error("Need reference_image")
|
59 |
|
|
|
77 |
left_mask = create_left_half_mask(reference_image)
|
78 |
top_mask = create_top_half_mask(reference_image)
|
79 |
|
80 |
+
color_matched = color_match(reference_image,target_image,color_match_format)
|
81 |
color_matched_resized = color_matched.resize(reference_image.size)
|
82 |
matched_path = save_image(color_matched.convert("RGB"))
|
83 |
images.append((matched_path,"color matched"))
|
84 |
+
progress(0.2)
|
85 |
+
|
86 |
reference_mix_left,reference_mix_right = create_compare_image(reference_image,color_matched_resized,left_mask)
|
87 |
images.append((save_image(reference_mix_left.convert("RGB"),extension="webp"),"mixed_left"))
|
88 |
images.append((save_image(reference_mix_right.convert("RGB"),extension="webp"),"mixed_right"))
|
89 |
+
progress(0.4)
|
90 |
|
91 |
reference_mix_top,reference_mix_bottom = create_compare_image(reference_image,color_matched_resized,top_mask)
|
92 |
images.append((save_image(reference_mix_top.convert("RGB"),extension="webp"),"mixed_top"))
|
93 |
images.append((save_image(reference_mix_bottom.convert("RGB"),extension="webp"),"mixed_bottom"))
|
94 |
+
progress(0.6)
|
95 |
|
96 |
color_matched_tone = apply_tone_curve(color_matched.convert("RGB"),curve_midtones,middle_tone_value)
|
97 |
color_matched_tone_resized = color_matched_tone.resize(reference_image.size)
|
|
|
100 |
reference_mix_left,reference_mix_right = create_compare_image(reference_image,color_matched_tone_resized,left_mask)
|
101 |
images.append((save_image(reference_mix_left.convert("RGB"),extension="webp"),"mixed_left"))
|
102 |
images.append((save_image(reference_mix_right.convert("RGB"),extension="webp"),"mixed_right"))
|
103 |
+
progress(0.8)
|
104 |
+
|
105 |
reference_mix_top,reference_mix_bottom = create_compare_image(reference_image,color_matched_tone_resized,top_mask)
|
106 |
images.append((save_image(reference_mix_top.convert("RGB"),extension="webp"),"mixed_top"))
|
107 |
images.append((save_image(reference_mix_bottom.convert("RGB"),extension="webp"),"mixed_bottom"))
|
108 |
+
progress(1.0)
|
109 |
|
110 |
return images
|
111 |
|
|
|
194 |
maximum=2.0,
|
195 |
step=0.01,
|
196 |
value=0.75)
|
197 |
+
color_match_format = gr.Dropdown(label="Format",choices=["RGB","CMYK","YCbCr","HSV","LAB"],value="RGB",info="RGB and CMYK seems same,others are broken")
|
198 |
|
199 |
with gr.Column():
|
200 |
image_out = gr.Gallery(height=800,label="Output", elem_id="output-img",format="webp", preview=True)
|
|
|
206 |
|
207 |
gr.on(
|
208 |
[btn1.click],
|
209 |
+
fn=process_images, inputs=[reference_image,target_image,mirror_target,middle_tone_value,color_match_format], outputs =[image_out], api_name='infer'
|
210 |
)
|
211 |
gr.Examples(
|
212 |
examples =[
|
demo_header.html
CHANGED
@@ -1,13 +1,18 @@
|
|
1 |
<div style="text-align: center;">
|
2 |
<h1>
|
3 |
-
Histgram Color Matching
|
4 |
</h1>
|
5 |
<div class="grid-container">
|
|
|
|
|
|
|
6 |
Body-to-body image color matching will never work; try face-to-face.keep eyes and hair color same<br>
|
7 |
Usually default is best.To similar lighting angle,mirror(flip horizental) is important<br>
|
8 |
Adding color paint(pink or green) can change hue(but not recommend to add target image)<br>
|
9 |
modify tone-curve adjust brightness.However most of the case it's the lighting's issue, so there's not much we can do <br>
|
|
|
10 |
</p>
|
11 |
</div>
|
|
|
12 |
|
13 |
</div>
|
|
|
1 |
<div style="text-align: center;">
|
2 |
<h1>
|
3 |
+
Histgram Color Matching(scikit-image)
|
4 |
</h1>
|
5 |
<div class="grid-container">
|
6 |
+
<img src="https://akjava.github.io/AIDiagramChatWithVoice-FaceCharacter/webp/128/00533245.webp" alt="Mediapipe Face Detection" class="image">
|
7 |
+
|
8 |
+
<p class="text">
|
9 |
Body-to-body image color matching will never work; try face-to-face.keep eyes and hair color same<br>
|
10 |
Usually default is best.To similar lighting angle,mirror(flip horizental) is important<br>
|
11 |
Adding color paint(pink or green) can change hue(but not recommend to add target image)<br>
|
12 |
modify tone-curve adjust brightness.However most of the case it's the lighting's issue, so there's not much we can do <br>
|
13 |
+
This is scikit-image version,maybe using another lib get another result I've never tried yet.
|
14 |
</p>
|
15 |
</div>
|
16 |
+
|
17 |
|
18 |
</div>
|
demo_tools.html
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
<div style="text-align: center;">
|
2 |
-
<p
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
<p></p>
|
4 |
</div>
|
|
|
1 |
<div style="text-align: center;">
|
2 |
+
<p>
|
3 |
+
<a href="https://huggingface.co/spaces/Akjava/mediapipe-face-detect">Mediapipe Face detector</a> |
|
4 |
+
<a href="https://huggingface.co/spaces/Akjava/mediapipe-face-crop-and-replace">Face Crop and Replace</a> |
|
5 |
+
<a href="https://huggingface.co/spaces/Akjava/mediapipe-68-points-facial-landmark">68 points landmark</a> |
|
6 |
+
<a href="https://huggingface.co/spaces/Akjava/mediapipe-68-points-facial-mask">Create 68 points Parts Mask</a> |
|
7 |
+
<a href="https://huggingface.co/spaces/Akjava/histgram-color-matching">Histgram Color Matching</a>
|
8 |
+
</p>
|
9 |
<p></p>
|
10 |
</div>
|