freealise commited on
Commit
adc979c
·
verified ·
1 Parent(s): ba907fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
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
- a_map[:,:,3] = ((255 - a_map[:,:,3]) / 255).astype(np.uint8)
220
- fr[:,:,0][a_map[:,:,3]>0] = (fr[:,:,0] * a_map[:,:,3] * 15 + 240).astype(np.uint8)
221
- fr[:,:,1][a_map[:,:,3]>0] = (fr[:,:,1] * a_map[:,:,3] * 15 + 240).astype(np.uint8)
222
- fr[:,:,2][a_map[:,:,3]>0] = (fr[:,:,2] * a_map[:,:,3] * 15 + 240).astype(np.uint8)
 
 
 
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"