gokaygokay commited on
Commit
257f308
1 Parent(s): 2c78421

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -171,29 +171,27 @@ def laplacian_blend(img1: np.ndarray, img2: np.ndarray, mask: np.ndarray, depth:
171
  if len(mask.shape) != len(img1.shape):
172
  mask = np.stack((mask,) * 3, axis=-1)
173
 
 
 
 
 
 
174
  mask_gaus_pyramid = _gaus_pyramid(mask, depth, sigma)
175
  img1_lap_pyramid, img2_lap_pyramid = _lap_pyramid(img1, depth, sigma), _lap_pyramid(img2, depth, sigma)
176
 
177
  blended = [_blend(obj, bg, mask) for obj, bg, mask in zip(img1_lap_pyramid, img2_lap_pyramid, mask_gaus_pyramid)][::-1]
178
 
179
- h, w = blended[0].shape[:2]
180
-
181
- img1 = cv2.resize(img1, (w, h))
182
- img2 = cv2.resize(img2, (w, h))
183
- mask = cv2.resize(mask, (w, h))
184
-
185
- blanded_img = _blend(img1, img2, mask)
186
- blanded_img = cv2.resize(blanded_img, blended[0].shape[:2])
187
 
188
- imgs = []
189
- for d in range(0, depth-1):
190
- gaussian_img = _low_pass_filter(blanded_img.copy(), sigma)
191
  reconstructed_img = cv2.add(blended[d], gaussian_img)
192
 
193
- imgs.append(reconstructed_img)
194
- blanded_img = cv2.pyrUp(reconstructed_img)
195
-
196
- return np.clip(imgs[-1], 0, 1)
197
 
198
  def get_image(img_path: str, mask: bool=False, scale: bool=True) -> np.array:
199
  """
 
171
  if len(mask.shape) != len(img1.shape):
172
  mask = np.stack((mask,) * 3, axis=-1)
173
 
174
+ # Resize all images to the same size (use the size of img1)
175
+ h, w = img1.shape[:2]
176
+ img2 = cv2.resize(img2, (w, h))
177
+ mask = cv2.resize(mask, (w, h))
178
+
179
  mask_gaus_pyramid = _gaus_pyramid(mask, depth, sigma)
180
  img1_lap_pyramid, img2_lap_pyramid = _lap_pyramid(img1, depth, sigma), _lap_pyramid(img2, depth, sigma)
181
 
182
  blended = [_blend(obj, bg, mask) for obj, bg, mask in zip(img1_lap_pyramid, img2_lap_pyramid, mask_gaus_pyramid)][::-1]
183
 
184
+ blended_img = _blend(img1, img2, mask)
 
 
 
 
 
 
 
185
 
186
+ for d in range(depth-1):
187
+ gaussian_img = _low_pass_filter(blended_img, sigma)
188
+ gaussian_img = cv2.resize(gaussian_img, blended[d].shape[:2]) # Ensure sizes match
189
  reconstructed_img = cv2.add(blended[d], gaussian_img)
190
 
191
+ blended_img = cv2.pyrUp(reconstructed_img)
192
+ blended_img = cv2.resize(blended_img, (w, h)) # Resize to original size
193
+
194
+ return np.clip(blended_img, 0, 1)
195
 
196
  def get_image(img_path: str, mask: bool=False, scale: bool=True) -> np.array:
197
  """