johnhelf commited on
Commit
891f612
·
1 Parent(s): 8e31ba0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -4,7 +4,7 @@ import numpy as np
4
  import gradio as gr
5
 
6
  import os
7
- from PIL import Image, ImageDraw
8
 
9
  from codeinterpreterapi import CodeInterpreterSession
10
 
@@ -12,20 +12,22 @@ from codeinterpreterapi import CodeInterpreterSession
12
  def imGreyAlpha(im):
13
  if isinstance(im,np.ndarray):
14
  im = Image.fromarray(im)
 
 
15
 
16
- grey = im.convert('L') # 转成灰度
17
- px = grey.load() # 获取灰度数组
18
 
19
- w,h = im.size # 获取图片大小
20
- im2 = Image.new(mode="RGBA", size=(w, h), color=(255,255,255,0)) # 新建图片
21
- draw = ImageDraw.Draw(im2) # 获取绘制句柄
22
 
23
 
24
- # 遍历像素点
25
- for i in range(w):
26
- for j in range(h):
27
- alpha = px[i, j] # 获取灰度作为alpha值
28
- draw.point((i, j), fill=(0, 0, 0, 255 - alpha)) # 填充像素点
29
  return im2 # 返回图像
30
 
31
 
 
4
  import gradio as gr
5
 
6
  import os
7
+ from PIL import Image, ImageDraw, ImageOps
8
 
9
  from codeinterpreterapi import CodeInterpreterSession
10
 
 
12
  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