-
Notifications
You must be signed in to change notification settings - Fork 24
/
DataPreprocessing.py
77 lines (49 loc) · 1.48 KB
/
DataPreprocessing.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
"""
Importing the required libraries.
"""
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import glob
from tqdm import tqdm
# In[10]:
"""
Displaying the sample sketch and color images.
"""
for file in glob.glob('train\*.png')[:5]:
f, a = plt.subplots(1,2, figsize=(10,5))
a = a.flatten()
img = Image.open(file).convert('RGB')
a[0].imshow(img.crop((0, 0, 512,512))); a[0].axis('off');
a[1].imshow(img.crop((512, 0, 1024, 512))); a[1].axis('off');
plt.show()
print(file)
# In[ ]:
"""
Creating a directory for training data.
"""
get_ipython().system('mkdir trainData')
# In[ ]:
"""
Preprocessing and saving the training data to corresponding directory.
"""
for idx, file in tqdm(enumerate(glob.glob('train\*.png'))):
img = Image.open(file).convert('RGB')
img.crop((0, 0, 512,512)).save('./trainData/Images/{}.png'.format(idx))
img.crop((512, 0, 1024, 512)).save('./trainData/Sketches/{}.png'.format(idx))
# In[ ]:
"""
Creating a directory for validation/test data.
"""
get_ipython().system('mkdir valData')
# In[ ]:
"""
Preprocessing and saving the validation/test data to corresponding directory.
"""
for idx, file in tqdm(enumerate(glob.glob('val\*.png'))):
img = Image.open(file).convert('RGB')
img.crop((0, 0, 512,512)).save('./valData/Images/{}.png'.format(idx))
img.crop((512, 0, 1024, 512)).save('./valData/Sketches/{}.png'.format(idx))