Spaces:
Build error
Build error
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import numpy as np
|
| 2 |
import cv2
|
|
|
|
| 3 |
|
| 4 |
def write_video(file_path, frames, fps):
|
| 5 |
"""
|
|
@@ -23,3 +24,22 @@ def write_video(file_path, frames, fps):
|
|
| 23 |
|
| 24 |
def dummy(images, **kwargs):
|
| 25 |
return images, False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import cv2
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
def write_video(file_path, frames, fps):
|
| 6 |
"""
|
|
|
|
| 24 |
|
| 25 |
def dummy(images, **kwargs):
|
| 26 |
return images, False
|
| 27 |
+
|
| 28 |
+
def preprocess_image(current_image, steps, image_size):
|
| 29 |
+
next_image = np.array(current_image.convert("RGBA"))*0
|
| 30 |
+
prev_image = current_image.resize((image_size-2*steps,image_size-2*steps))
|
| 31 |
+
prev_image = prev_image.convert("RGBA")
|
| 32 |
+
prev_image = np.array(prev_image)
|
| 33 |
+
next_image[:, :, 3] = 1
|
| 34 |
+
next_image[steps:image_size-steps,steps:image_size-steps,:] = prev_image
|
| 35 |
+
prev_image = Image.fromarray(next_image)
|
| 36 |
+
|
| 37 |
+
return prev_image
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def preprocess_mask_image(current_image):
|
| 41 |
+
mask_image = np.array(current_image)[:,:,3] # assume image has alpha mask (use .mode to check for "RGBA")
|
| 42 |
+
mask_image = Image.fromarray(255-mask_image).convert("RGB")
|
| 43 |
+
current_image = current_image.convert("RGB")
|
| 44 |
+
|
| 45 |
+
return current_image, mask_image
|