Spaces:
Runtime error
Runtime error
gokaygokay
commited on
Commit
•
9c52723
1
Parent(s):
e2763db
Update app.py
Browse files
app.py
CHANGED
@@ -184,24 +184,26 @@ def laplacian_blend(img1: np.ndarray, img2: np.ndarray, mask: np.ndarray, depth:
|
|
184 |
|
185 |
return np.clip(imgs[-1], 0, 1)
|
186 |
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
|
|
|
|
|
|
193 |
else:
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
if mask:
|
198 |
if len(img.shape) == 3:
|
199 |
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
200 |
-
|
201 |
-
return np.where(binary_mask == 255, 1, 0)
|
202 |
|
203 |
-
if scale:
|
204 |
-
return img.astype('
|
205 |
|
206 |
return img
|
207 |
|
@@ -253,11 +255,11 @@ with gr.Blocks(theme='bethecloud/storj_theme') as iface:
|
|
253 |
)
|
254 |
|
255 |
gr.Examples(
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
inputs=[bg_img, obj_img, mask_img, method],
|
262 |
outputs=output_image,
|
263 |
fn=blend_images,
|
|
|
184 |
|
185 |
return np.clip(imgs[-1], 0, 1)
|
186 |
|
187 |
+
|
188 |
+
|
189 |
+
def get_image(img_input, mask=False, scale=True):
|
190 |
+
if isinstance(img_input, dict) and 'composite' in img_input:
|
191 |
+
img = img_input['composite']
|
192 |
+
elif isinstance(img_input, np.ndarray):
|
193 |
+
img = img_input
|
194 |
+
elif isinstance(img_input, str):
|
195 |
+
img = cv2.imread(img_input)
|
196 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
197 |
else:
|
198 |
+
raise ValueError("Unsupported image input type")
|
199 |
+
|
|
|
200 |
if mask:
|
201 |
if len(img.shape) == 3:
|
202 |
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
203 |
+
return np.where(img > 127, 1, 0) # Threshold at 127 for the mask
|
|
|
204 |
|
205 |
+
if scale and img.dtype != np.float64:
|
206 |
+
return img.astype('float64') / 255.0
|
207 |
|
208 |
return img
|
209 |
|
|
|
255 |
)
|
256 |
|
257 |
gr.Examples(
|
258 |
+
examples=[
|
259 |
+
["img1.jpg", "img2.jpg", {"composite": "mask1.jpg"}, "Poisson"],
|
260 |
+
["img3.jpg", "img4.jpg", {"composite": "mask2.jpg"}, "Mixed Gradient"],
|
261 |
+
["img6.jpg", "img9.jpg", {"composite": "mask3.jpg"}, "Laplacian"]
|
262 |
+
],
|
263 |
inputs=[bg_img, obj_img, mask_img, method],
|
264 |
outputs=output_image,
|
265 |
fn=blend_images,
|