-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_bg_gmm.py
31 lines (22 loc) · 909 Bytes
/
gen_bg_gmm.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
import os
import sys
import numpy as np
from PIL import Image
from method1 import restore_background
if __name__ == '__main__':
in_path = '../data/Ourdata_allRawImage/ISI-letters_dataset/Data/'
out_path = '../data/Ourdata_allRawImage/ISI-letters_dataset/bg'
in_files = sorted(os.listdir(in_path))
for i in range(len(in_files)):
sys.stdout.write('Progress: [{}/{}]\r'.format(i, len(in_files)))
in_file_name, ext = os.path.splitext(in_files[i])
out_file = in_file_name+'_bg'+ext
im_PIL = Image.open(os.path.join(in_path, in_files[i]))
if im_PIL.mode != 'RGB':
im_PIL = im_PIL.convert('RGB')
im_uint8 = np.asarray(im_PIL)
im = im_uint8/255.0
bg = restore_background(im, im_PIL)
bg_PIL = Image.fromarray(np.squeeze(bg).astype('uint8'))
bg_PIL.save(os.path.join(out_path, out_file))
print('')