Spaces:
Running
on
Zero
Running
on
Zero
tori29umai
commited on
Commit
•
05d9ddd
1
Parent(s):
c306a0f
Update utils/image_utils.py
Browse files- utils/image_utils.py +12 -25
utils/image_utils.py
CHANGED
@@ -1,31 +1,18 @@
|
|
1 |
from PIL import Image, ImageOps
|
2 |
import numpy as np
|
3 |
import cv2
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
image_pil = canvas_image.convert("RGB")
|
17 |
-
image_np = np.array(image_pil)
|
18 |
-
|
19 |
-
# グレースケール変換
|
20 |
-
gray = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
|
21 |
-
# Cannyエッジ検出
|
22 |
-
edges = cv2.Canny(gray, threshold1, threshold2)
|
23 |
-
|
24 |
-
canny = Image.fromarray(edges)
|
25 |
-
|
26 |
-
|
27 |
-
return canny
|
28 |
-
|
29 |
|
30 |
def resize_image_aspect_ratio(image):
|
31 |
# 元の画像サイズを取得
|
|
|
1 |
from PIL import Image, ImageOps
|
2 |
import numpy as np
|
3 |
import cv2
|
4 |
+
from rembg import remove
|
5 |
+
|
6 |
+
def remove_background(input_image):
|
7 |
+
rgba_image = remove(input_image)
|
8 |
+
# アルファチャネルをマスクとして使用
|
9 |
+
alpha_channel = rgba_image[:, :, 3]
|
10 |
+
|
11 |
+
# 白い背景画像を作成
|
12 |
+
background = np.ones_like(rgba_image, dtype=np.uint8) * 255
|
13 |
+
# マスクを適用
|
14 |
+
background_masked = cv2.bitwise_and(background, background, mask=alpha_channel)
|
15 |
+
return background_masked
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
def resize_image_aspect_ratio(image):
|
18 |
# 元の画像サイズを取得
|