gaur3009 commited on
Commit
24d82c0
·
verified ·
1 Parent(s): 96fe22f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -26,21 +26,23 @@ def segment_dress(image):
26
  def warp_design(design, mask, warp_scale):
27
  """Warp the design using TPS and scale control."""
28
  h, w = mask.shape[:2]
 
 
29
  design_resized = cv2.resize(design, (w, h))
30
 
31
- # Normalize mask, convert to uint8
32
- scaled_mask = (mask * 255).astype(np.uint8)
33
-
34
- # Ensure single-channel mask
35
- if len(scaled_mask.shape) == 3 and scaled_mask.shape[2] == 3:
36
- scaled_mask = cv2.cvtColor(scaled_mask, cv2.COLOR_BGR2GRAY)
 
37
 
38
- # Resize the mask if needed
39
- if scaled_mask.shape != (h, w):
40
- scaled_mask = cv2.resize(scaled_mask, (w, h), interpolation=cv2.INTER_NEAREST)
41
 
42
- print(f"Design Resized Shape: {design_resized.shape}, Mask Shape: {scaled_mask.shape}")
43
- return cv2.bitwise_and(design_resized, design_resized, mask=scaled_mask)
44
 
45
  def blend_images(base, overlay, mask):
46
  """Blends the design onto the dress using seamless cloning."""
 
26
  def warp_design(design, mask, warp_scale):
27
  """Warp the design using TPS and scale control."""
28
  h, w = mask.shape[:2]
29
+
30
+ # Resize design to match mask dimensions
31
  design_resized = cv2.resize(design, (w, h))
32
 
33
+ # Ensure mask is single-channel grayscale
34
+ if len(mask.shape) == 3:
35
+ mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
36
+
37
+ # Ensure mask is uint8
38
+ if mask.dtype != np.uint8:
39
+ mask = (mask * 255).astype(np.uint8)
40
 
41
+ # Convert design_resized to 3-channel if it's grayscale
42
+ if len(design_resized.shape) == 2:
43
+ design_resized = cv2.cvtColor(design_resized, cv2.COLOR_GRAY2BGR)
44
 
45
+ return cv2.bitwise_and(design_resized, design_resized, mask=mask)
 
46
 
47
  def blend_images(base, overlay, mask):
48
  """Blends the design onto the dress using seamless cloning."""