johnhelf commited on
Commit
a628810
·
1 Parent(s): 9e4b401

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -13,7 +13,7 @@ def imGreyAlpha(im):
13
  if isinstance(im,np.ndarray):
14
  im = Image.fromarray(im)
15
 
16
- im = ImageOps.invert(im)
17
 
18
  grey = im.convert('L') # 转成灰度
19
  px = grey.load() # 获取灰度数组
@@ -27,7 +27,10 @@ def imGreyAlpha(im):
27
  for i in range(w):
28
  for j in range(h):
29
  alpha = px[i, j] # 获取灰度作为alpha值
30
- draw.point((i, j), fill=(0, 0, 0, 255 - alpha)) # 填充像素点
 
 
 
31
 
32
 
33
  return im2 # 返回图像
 
13
  if isinstance(im,np.ndarray):
14
  im = Image.fromarray(im)
15
 
16
+ # im = ImageOps.invert(im)
17
 
18
  grey = im.convert('L') # 转成灰度
19
  px = grey.load() # 获取灰度数组
 
27
  for i in range(w):
28
  for j in range(h):
29
  alpha = px[i, j] # 获取灰度作为alpha值
30
+ if alpha == 0:
31
+ draw.point((i,j), fill=(0,0,0,0))
32
+ else:
33
+ draw.point((i, j), fill=(0, 0, 0, alpha)) # 填充像素点
34
 
35
 
36
  return im2 # 返回图像