Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,7 @@ import gradio as gr
|
|
| 14 |
|
| 15 |
from huggingface_hub import snapshot_download
|
| 16 |
from image_tools.sizes import resize_and_crop
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
model = snapshot_download(repo_id="akhaliq/frame-interpolation-film-style")
|
|
@@ -200,9 +201,25 @@ def remove_bg(fl, count, mh, ms, md, lm):
|
|
| 200 |
fr_fg[fr_fg>0] = 3 #probable fg
|
| 201 |
mask, bgdModel, fgdModel = cv2.grabCut(fr, fr_fg, None,None,None,31, cv2.GC_INIT_WITH_MASK)
|
| 202 |
mask = np.where((mask==2)|(mask==0),0,1).astype('uint8')
|
| 203 |
-
fr[mask==0] = (255,255,255)
|
| 204 |
|
| 205 |
cv2.imwrite(fl, fr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
return fl
|
| 207 |
else: # even: with the flash
|
| 208 |
fl_ = fl.split(".")[0] + "_.png"
|
|
|
|
| 14 |
|
| 15 |
from huggingface_hub import snapshot_download
|
| 16 |
from image_tools.sizes import resize_and_crop
|
| 17 |
+
from pymatting import cutout
|
| 18 |
|
| 19 |
|
| 20 |
model = snapshot_download(repo_id="akhaliq/frame-interpolation-film-style")
|
|
|
|
| 201 |
fr_fg[fr_fg>0] = 3 #probable fg
|
| 202 |
mask, bgdModel, fgdModel = cv2.grabCut(fr, fr_fg, None,None,None,31, cv2.GC_INIT_WITH_MASK)
|
| 203 |
mask = np.where((mask==2)|(mask==0),0,1).astype('uint8')
|
| 204 |
+
#fr[mask==0] = (255,255,255)
|
| 205 |
|
| 206 |
cv2.imwrite(fl, fr)
|
| 207 |
+
|
| 208 |
+
b = 15
|
| 209 |
+
element = cv2.getStructuringElement(cv2.MORPH_RECT, (2 * b + 1, 2 * b + 1), (b, b))
|
| 210 |
+
mask_e = cv2.erode(mask, element) * 255
|
| 211 |
+
mask_d = cv2.dilate(mask, element) * 127
|
| 212 |
+
mask_d[mask_e>0] = 255
|
| 213 |
+
cv2.imwrite(f"{str(count)}_trimask.png", mask_d.astype(np.uint8))
|
| 214 |
+
|
| 215 |
+
cutout(
|
| 216 |
+
# input image path
|
| 217 |
+
fl,
|
| 218 |
+
# input trimap path
|
| 219 |
+
f"{str(count)}_trimask.png",
|
| 220 |
+
# output cutout path
|
| 221 |
+
fl)
|
| 222 |
+
|
| 223 |
return fl
|
| 224 |
else: # even: with the flash
|
| 225 |
fl_ = fl.split(".")[0] + "_.png"
|