-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgTransparency.py
56 lines (45 loc) · 1.39 KB
/
bgTransparency.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from lib2to3.pytree import convert
import cv2
import numpy as np
from PIL import Image
import os
src1 = cv2.imread('./testImg/background2.png') #배경파일 읽기
src2 = cv2.imread('./testimg/No1.jpg')
#이미지 배경 투명하게 만들기
def imgTransparency(img_dir) :
os.chdir(img_dir) #해당 폴더로 이동
files = os.listdir(img_dir) #해당 폴더에 있는 파일 이름을 리스트 형태로 받음
png_img = []
jpg_img = []
for img in files :
if'.png' in img:
i = 10
f = cv2.imread(img)
png_img.append(f)
img = Image.open(img)
img = img.convert("RGBA")
datas = img.getdata()
newData = []
cutoff = 100
for item in datas:
if item[0] >= cutoff and item[1] >= cutoff and item[2] >= cutoff:
newData.append((255, 255, 255, 0))
else:
newData.append(item)
img.putdata(newData)
img.save(img_dir+str(i)+'.png', "PNG")
i += 1
img = Image.open('./testImg/combi.png')
img = img.convert("RGBA")
datas = img.getdata()
newData = []
cutoff = 100
for item in datas:
if item[0] >= cutoff and item[1] >= cutoff and item[2] >= cutoff:
newData.append((255, 255, 255, 0))
else:
newData.append(item)
img.putdata(newData)
img.save("./testImg/newcombi.png", "PNG")
cv2.waitKeyEx()
cv2.destroyAllWindows()