Update app.py
Browse files
app.py
CHANGED
|
@@ -216,10 +216,13 @@ def remove_bg(fl, count, mh, ms, md, lm):
|
|
| 216 |
cutout(fl, f"{str(count)}_trimask.png", f"{str(count)}_cutout.png")
|
| 217 |
|
| 218 |
a_map = cv2.imread(f"{str(count)}_cutout.png", cv2.IMREAD_UNCHANGED).astype(np.uint8)
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
cv2.imwrite(fl, fr)
|
| 225 |
return fl #f"{str(count)}_cutout.png"
|
|
|
|
| 216 |
cutout(fl, f"{str(count)}_trimask.png", f"{str(count)}_cutout.png")
|
| 217 |
|
| 218 |
a_map = cv2.imread(f"{str(count)}_cutout.png", cv2.IMREAD_UNCHANGED).astype(np.uint8)
|
| 219 |
+
B, G, R, A = cv2.split(a_map)
|
| 220 |
+
alpha = A / 255
|
| 221 |
+
|
| 222 |
+
R = (255 * (1 - alpha) + R * alpha).astype(np.uint8)
|
| 223 |
+
G = (255 * (1 - alpha) + G * alpha).astype(np.uint8)
|
| 224 |
+
B = (255 * (1 - alpha) + B * alpha).astype(np.uint8)
|
| 225 |
+
fr = cv2.merge((B, G, R))
|
| 226 |
|
| 227 |
cv2.imwrite(fl, fr)
|
| 228 |
return fl #f"{str(count)}_cutout.png"
|