[ad8447]: / (2) PyTorch_HistoTNet / util / dbToDataStore.py

Download this file

51 lines (41 with data), 1.3 kB

 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
import os
import matplotlib.pyplot as plt
from util.pause import pause
def dbToDataStore(dirIn, dirOut, extOrig, extNew, log):
# display
if log:
print("Transforming DB...")
# transform db
for name in os.listdir(dirIn):
if name.endswith(extOrig):
# display
#if log:
#print("\tProcessing: " + name)
# read name
pre, ext = os.path.splitext(name)
# get label
C = pre.split('_')
# create dir with label
dirOutLabel = os.path.join(dirOut, C[1])
# newname
newName = pre + '.' + extNew
newPath = os.path.join(dirOutLabel, newName)
# if already present skip
if os.path.exists(newPath):
continue
# create directory if not present
if not os.path.exists(dirOutLabel):
os.makedirs(dirOutLabel)
# read
img = plt.imread(os.path.join(dirIn, name))
# display
"""
print(newName)
plt.imshow(img)
plt.show()
pause()
"""
# write
plt.imsave(newPath, img)
#pause()
print()