-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathtesting.py
40 lines (34 loc) · 1.11 KB
/
testing.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
import fnmatch
import os
import numpy as np
from PIL import Image
def find_files(directory, pattern='*.jpg'):
'''Recursively finds all files matching the pattern.'''
files = []
for root, dirnames, filenames in os.walk(directory):
for filename in fnmatch.filter(filenames, pattern):
files.append(os.path.join(root, filename))
return files
def _read_image(filename):
return Image.open(filename).convert('L')
def load_generic_text(directory):
'''Generator that yields image raw from the directory.'''
files = find_files(directory)
for filename in files:
pic = _read_image(filename)
pic = pic.resize((128,128), Image.ANTIALIAS)
img = np.array(pic)
print (img)
img = img.reshape(-1, 1)
print (img)
img = img.reshape(128, 128)
print(img)
new_img = Image.fromarray(img)
new_img.save('output_file.jpg')
yield img, filename
def main():
iterator = load_generic_text("./data")
for text, filename in iterator:
print ("Filename", filename)
if __name__ == '__main__':
main()