johnhelf commited on
Commit
42d1f6b
·
1 Parent(s): 891f612

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -13,21 +13,23 @@ def imGreyAlpha(im):
13
  if isinstance(im,np.ndarray):
14
  im = Image.fromarray(im)
15
 
16
- im2 = ImageOps.invert(im)
17
 
18
- # grey = im.convert('L') # 转成灰度
19
- # px = grey.load() # 获取灰度数组
 
20
 
21
- # w,h = im.size # 获取图片大小
22
- # im2 = Image.new(mode="RGBA", size=(w, h), color=(255,255,255,0)) # 新建图片
23
- # draw = ImageDraw.Draw(im2) # 获取绘制句柄
24
 
25
 
26
- # # 遍历像素点
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
  return im2 # 返回图像
32
 
33
 
 
13
  if isinstance(im,np.ndarray):
14
  im = Image.fromarray(im)
15
 
 
16
 
17
+
18
+ grey = im.convert('L') # 转成灰度
19
+ px = grey.load() # 获取灰度数组
20
 
21
+ w,h = im.size # 获取图片大小
22
+ im2 = Image.new(mode="RGBA", size=(w, h), color=(255,255,255,0)) # 新建图片
23
+ draw = ImageDraw.Draw(im2) # 获取绘制句柄
24
 
25
 
26
+ # 遍历像素点
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
+ im2 = ImageOps.invert(im2)
33
  return im2 # 返回图像
34
 
35