gokaygokay commited on
Commit
6424be8
1 Parent(s): 510b9e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -198,7 +198,7 @@ def get_image(img_input, mask=False, scale=True):
198
  if mask:
199
  if len(img.shape) == 3:
200
  img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
201
- return np.where(img > 127, 1, 0) # Threshold at 127 for the mask
202
 
203
  if scale and img.dtype != np.float64:
204
  return img.astype('float64') / 255.0
@@ -208,6 +208,9 @@ def get_image(img_input, mask=False, scale=True):
208
  def blend_images(bg_img, obj_img, mask_img, method):
209
  bg_img = get_image(bg_img)
210
  obj_img = get_image(obj_img)
 
 
 
211
  mask_img = get_image(mask_img, mask=True)
212
 
213
  if method == "Poisson":
@@ -257,11 +260,11 @@ with gr.Blocks(theme='bethecloud/storj_theme') as iface:
257
  )
258
 
259
  gr.Examples(
260
- examples=[
261
- ["img1.jpg", "img2.jpg", "mask1.jpg", "Poisson"],
262
- ["img3.jpg", "img4.jpg", "mask2.jpg", "Mixed Gradient"],
263
- ["img6.jpg", "img9.jpg", "mask3.jpg", "Laplacian"]
264
- ],
265
  inputs=[bg_img, obj_img, mask_img, method],
266
  outputs=output_image,
267
  fn=blend_images,
 
198
  if mask:
199
  if len(img.shape) == 3:
200
  img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
201
+ return np.where(img > 127, 1, 0).astype(np.uint8) # Threshold at 127 for the mask
202
 
203
  if scale and img.dtype != np.float64:
204
  return img.astype('float64') / 255.0
 
208
  def blend_images(bg_img, obj_img, mask_img, method):
209
  bg_img = get_image(bg_img)
210
  obj_img = get_image(obj_img)
211
+
212
+ if isinstance(mask_img, str):
213
+ mask_img = cv2.imread(mask_img, cv2.IMREAD_GRAYSCALE)
214
  mask_img = get_image(mask_img, mask=True)
215
 
216
  if method == "Poisson":
 
260
  )
261
 
262
  gr.Examples(
263
+ examples=[
264
+ ["img1.jpg", "img2.jpg", "mask1.jpg", "Poisson"],
265
+ ["img3.jpg", "img4.jpg", "mask2.jpg", "Mixed Gradient"],
266
+ ["img6.jpg", "img9.jpg", "mask3.jpg", "Laplacian"]
267
+ ],
268
  inputs=[bg_img, obj_img, mask_img, method],
269
  outputs=output_image,
270
  fn=blend_images,