-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_transform.py
38 lines (28 loc) · 918 Bytes
/
image_transform.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
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from os import listdir
from os.path import isfile, join
def get_files(folder: str) -> list:
"""
git files from directory
:return:
"""
return [f for f in listdir(folder) if isfile(join(folder, f))]
def run():
data_folder = "data"
dest_folder = "data_prepared"
THRESHOLD_VALUE = 254
for x, f in enumerate(get_files(folder=data_folder)):
# img = "data/15033728.png"
img = join(data_folder, f)
with Image.open(img) as im:
plt.axis("off")
im.convert("L")
imgData = np.asarray(im)
thresholdedData = (imgData > THRESHOLD_VALUE) * 1.0
plt.imshow(X=thresholdedData)
plt.savefig(join(dest_folder, f), transparent=True, bbox_inches="tight", pad_inches=0)
plt.clf()
if __name__ == "__main__":
run()