Spaces:
Runtime error
Runtime error
gokaygokay
commited on
Commit
•
ceab301
1
Parent(s):
257f308
Update app.py
Browse files
app.py
CHANGED
@@ -160,15 +160,14 @@ def _blend(img1: np.ndarray, img2: np.ndarray, mask: np.ndarray) -> np.ndarray:
|
|
160 |
return img1 * mask + img2 * (1.0 - mask)
|
161 |
|
162 |
def laplacian_blend(img1: np.ndarray, img2: np.ndarray, mask: np.ndarray, depth: int, sigma: int) -> np.ndarray:
|
163 |
-
# Ensure both images have the same number of channels
|
164 |
-
if len(img1.shape)
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
img2 = cv2.cvtColor(img2, cv2.COLOR_GRAY2RGB)
|
169 |
|
170 |
-
# Ensure mask has
|
171 |
-
if len(mask.shape)
|
172 |
mask = np.stack((mask,) * 3, axis=-1)
|
173 |
|
174 |
# Resize all images to the same size (use the size of img1)
|
@@ -185,11 +184,18 @@ def laplacian_blend(img1: np.ndarray, img2: np.ndarray, mask: np.ndarray, depth:
|
|
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])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
193 |
|
194 |
return np.clip(blended_img, 0, 1)
|
195 |
|
|
|
160 |
return img1 * mask + img2 * (1.0 - mask)
|
161 |
|
162 |
def laplacian_blend(img1: np.ndarray, img2: np.ndarray, mask: np.ndarray, depth: int, sigma: int) -> np.ndarray:
|
163 |
+
# Ensure both images have the same number of channels (3 for RGB)
|
164 |
+
if len(img1.shape) == 2:
|
165 |
+
img1 = cv2.cvtColor(img1, cv2.COLOR_GRAY2RGB)
|
166 |
+
if len(img2.shape) == 2:
|
167 |
+
img2 = cv2.cvtColor(img2, cv2.COLOR_GRAY2RGB)
|
|
|
168 |
|
169 |
+
# Ensure mask has 3 channels
|
170 |
+
if len(mask.shape) == 2:
|
171 |
mask = np.stack((mask,) * 3, axis=-1)
|
172 |
|
173 |
# Resize all images to the same size (use the size of img1)
|
|
|
184 |
|
185 |
for d in range(depth-1):
|
186 |
gaussian_img = _low_pass_filter(blended_img, sigma)
|
187 |
+
gaussian_img = cv2.resize(gaussian_img, blended[d].shape[:2])
|
188 |
+
|
189 |
+
# Ensure both images have 3 channels
|
190 |
+
if len(blended[d].shape) == 2:
|
191 |
+
blended[d] = cv2.cvtColor(blended[d], cv2.COLOR_GRAY2RGB)
|
192 |
+
if len(gaussian_img.shape) == 2:
|
193 |
+
gaussian_img = cv2.cvtColor(gaussian_img, cv2.COLOR_GRAY2RGB)
|
194 |
+
|
195 |
reconstructed_img = cv2.add(blended[d], gaussian_img)
|
196 |
|
197 |
blended_img = cv2.pyrUp(reconstructed_img)
|
198 |
+
blended_img = cv2.resize(blended_img, (w, h))
|
199 |
|
200 |
return np.clip(blended_img, 0, 1)
|
201 |
|