Spaces:
Runtime error
Runtime error
gokaygokay
commited on
Commit
•
2c78421
1
Parent(s):
7b1b238
Update app.py
Browse files
app.py
CHANGED
@@ -160,6 +160,17 @@ 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 |
mask_gaus_pyramid = _gaus_pyramid(mask, depth, sigma)
|
164 |
img1_lap_pyramid, img2_lap_pyramid = _lap_pyramid(img1, depth, sigma), _lap_pyramid(img2, depth, sigma)
|
165 |
|
|
|
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) != len(img2.shape):
|
165 |
+
if len(img1.shape) == 2:
|
166 |
+
img1 = cv2.cvtColor(img1, cv2.COLOR_GRAY2RGB)
|
167 |
+
elif len(img2.shape) == 2:
|
168 |
+
img2 = cv2.cvtColor(img2, cv2.COLOR_GRAY2RGB)
|
169 |
+
|
170 |
+
# Ensure mask has the same number of channels as the images
|
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 |
|