Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -68,7 +68,7 @@ def recolor_dress(image_np, dress_mask, target_color):
|
|
68 |
|
69 |
mean_L, mean_A, mean_B = np.mean(dress_pixels, axis=0)
|
70 |
|
71 |
-
# Apply
|
72 |
a_shift = target_color_lab[1] - mean_A
|
73 |
b_shift = target_color_lab[2] - mean_B
|
74 |
img_lab[..., 1] = np.clip(img_lab[..., 1] + (dress_mask / 255.0) * a_shift, 0, 255)
|
@@ -78,19 +78,20 @@ def recolor_dress(image_np, dress_mask, target_color):
|
|
78 |
img_recolored = cv2.cvtColor(img_lab.astype(np.uint8), cv2.COLOR_LAB2RGB)
|
79 |
|
80 |
# Create feathered mask for smooth blending
|
|
|
81 |
feathered_mask = cv2.GaussianBlur(dress_mask, (15, 15), 5)
|
|
|
82 |
|
83 |
# Blend the recolored dress with the original image
|
84 |
-
img_final = (image_np * (1 -
|
85 |
|
86 |
return img_final
|
87 |
|
88 |
-
def change_dress_color(
|
89 |
"""Main function to change dress color naturally"""
|
90 |
-
if
|
91 |
return None
|
92 |
|
93 |
-
img = Image.open(image_path).convert("RGB")
|
94 |
img_np = np.array(img)
|
95 |
|
96 |
# Get dress segmentation mask
|
@@ -119,7 +120,7 @@ def change_dress_color(image_path, color):
|
|
119 |
demo = gr.Interface(
|
120 |
fn=change_dress_color,
|
121 |
inputs=[
|
122 |
-
gr.Image(type="
|
123 |
gr.Radio(["Red", "Blue", "Green", "Yellow", "Purple", "Orange", "Cyan", "Magenta", "White", "Black"], label="Choose New Dress Color")
|
124 |
],
|
125 |
outputs=gr.Image(type="pil", label="Color Changed Dress"),
|
|
|
68 |
|
69 |
mean_L, mean_A, mean_B = np.mean(dress_pixels, axis=0)
|
70 |
|
71 |
+
# Apply LAB shift
|
72 |
a_shift = target_color_lab[1] - mean_A
|
73 |
b_shift = target_color_lab[2] - mean_B
|
74 |
img_lab[..., 1] = np.clip(img_lab[..., 1] + (dress_mask / 255.0) * a_shift, 0, 255)
|
|
|
78 |
img_recolored = cv2.cvtColor(img_lab.astype(np.uint8), cv2.COLOR_LAB2RGB)
|
79 |
|
80 |
# Create feathered mask for smooth blending
|
81 |
+
lightness_mask = (img_lab[..., 0] / 255.0)
|
82 |
feathered_mask = cv2.GaussianBlur(dress_mask, (15, 15), 5)
|
83 |
+
adaptive_feather = (feathered_mask * lightness_mask).astype(np.uint8)
|
84 |
|
85 |
# Blend the recolored dress with the original image
|
86 |
+
img_final = (image_np * (1 - adaptive_feather[..., None] / 255) + img_recolored * (adaptive_feather[..., None] / 255)).astype(np.uint8)
|
87 |
|
88 |
return img_final
|
89 |
|
90 |
+
def change_dress_color(img, color):
|
91 |
"""Main function to change dress color naturally"""
|
92 |
+
if img is None:
|
93 |
return None
|
94 |
|
|
|
95 |
img_np = np.array(img)
|
96 |
|
97 |
# Get dress segmentation mask
|
|
|
120 |
demo = gr.Interface(
|
121 |
fn=change_dress_color,
|
122 |
inputs=[
|
123 |
+
gr.Image(type="pil", label="Upload Dress Image"),
|
124 |
gr.Radio(["Red", "Blue", "Green", "Yellow", "Purple", "Orange", "Cyan", "Magenta", "White", "Black"], label="Choose New Dress Color")
|
125 |
],
|
126 |
outputs=gr.Image(type="pil", label="Color Changed Dress"),
|