gaur3009 commited on
Commit
7d41451
·
verified ·
1 Parent(s): 7bda381

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -25,7 +25,7 @@ def estimate_depth(image):
25
  return depth.astype(np.uint8)
26
 
27
  def blend_design(cloth_img, design_img):
28
- """Blend design onto clothing naturally."""
29
  cloth_img = cloth_img.convert("RGB")
30
  design_img = design_img.convert("RGBA")
31
  cloth_np = np.array(cloth_img)
@@ -38,9 +38,9 @@ def blend_design(cloth_img, design_img):
38
  new_w, new_h = int(dw * scale_factor), int(dh * scale_factor)
39
  design_np = cv2.resize(design_np, (new_w, new_h), interpolation=cv2.INTER_AREA)
40
 
41
- # Convert design to include transparency effect
42
- alpha_channel = design_np[:, :, 3] / 255.0 # Extract alpha channel
43
- design_np = design_np[:, :, :3] # Remove alpha channel for processing
44
 
45
  # Create a blank canvas and paste the resized design at the center
46
  x_offset = (w - new_w) // 2
@@ -59,8 +59,8 @@ def blend_design(cloth_img, design_img):
59
  # Generate displacement map based on depth
60
  displacement_x = cv2.Sobel(depth_map, cv2.CV_32F, 1, 0, ksize=5)
61
  displacement_y = cv2.Sobel(depth_map, cv2.CV_32F, 0, 1, ksize=5)
62
- displacement_x = cv2.normalize(displacement_x, None, -3, 3, cv2.NORM_MINMAX)
63
- displacement_y = cv2.normalize(displacement_y, None, -3, 3, cv2.NORM_MINMAX)
64
 
65
  # Warp design using displacement map
66
  map_x, map_y = np.meshgrid(np.arange(w), np.arange(h))
 
25
  return depth.astype(np.uint8)
26
 
27
  def blend_design(cloth_img, design_img):
28
+ """Blend design onto clothing naturally with fold adaptation."""
29
  cloth_img = cloth_img.convert("RGB")
30
  design_img = design_img.convert("RGBA")
31
  cloth_np = np.array(cloth_img)
 
38
  new_w, new_h = int(dw * scale_factor), int(dh * scale_factor)
39
  design_np = cv2.resize(design_np, (new_w, new_h), interpolation=cv2.INTER_AREA)
40
 
41
+ # Extract alpha channel for transparency
42
+ alpha_channel = design_np[:, :, 3] / 255.0
43
+ design_np = design_np[:, :, :3]
44
 
45
  # Create a blank canvas and paste the resized design at the center
46
  x_offset = (w - new_w) // 2
 
59
  # Generate displacement map based on depth
60
  displacement_x = cv2.Sobel(depth_map, cv2.CV_32F, 1, 0, ksize=5)
61
  displacement_y = cv2.Sobel(depth_map, cv2.CV_32F, 0, 1, ksize=5)
62
+ displacement_x = cv2.normalize(displacement_x, None, -5, 5, cv2.NORM_MINMAX)
63
+ displacement_y = cv2.normalize(displacement_y, None, -5, 5, cv2.NORM_MINMAX)
64
 
65
  # Warp design using displacement map
66
  map_x, map_y = np.meshgrid(np.arange(w), np.arange(h))