File size: 8,530 Bytes
6263bf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import os
import pandas as pd
import shutil
from tqdm import tqdm

# <<---->> HKPolyU training
dstn_fold = "< Path to parent data folder >"

cb_df = pd.read_csv("< csv file for HKPolyU train dataset with CB paths and IDS >")
cl_df = pd.read_csv("< csv file for HKPolyU train dataset with CL paths and IDS >")

subject_id = cb_df['ids'].tolist()
files = cb_df['Filename'].tolist()
for i in tqdm(range(len(subject_id))):
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]))):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i])))
    finger_id = files[i].split('/')[-1].split('.')[0].split('_')[-1]
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]),finger_id)):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i]),finger_id))
    shutil.copy(files[i],os.path.join(dstn_fold,str(subject_id[i]),finger_id,'cb.jpg'))
count=0
subject_id = cl_df['ids'].tolist()
files = cl_df['Filename'].tolist()
for i in tqdm(range(len(subject_id))):
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]))):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i])))
    finger_id = files[i].split('/')[-1].split('.')[0].split('_')[-1]
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]),finger_id)):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i]),finger_id))
    shutil.copy(files[i].replace("hkpoly_data/cl", "hkpoly_data/cl_png/cl/").replace(".bmp", ".png"),os.path.join(dstn_fold,str(subject_id[i]),finger_id,'cl.png'))
    count+=1

# <<---->> Ridgebase training
dstn_fold = "< Path to parent data folder >"

cb_df = pd.read_csv("< csv file for RB train dataset with CB paths and IDS >")
cl_df = pd.read_csv("< csv file for RB train dataset with CL paths and IDS >")

files = cl_df['Filename'].tolist()
sub_lst = list()
for i in tqdm(files):
    sub_id = os.path.splitext(i.split("/")[-1])[0].split("_")[2]
    if not os.path.exists(os.path.join(dstn_fold,sub_id)):
        os.mkdir(os.path.join(dstn_fold,sub_id))
    sess = os.path.splitext(i.split("/")[-1])[0].split("_")[0]
    back = os.path.splitext(i.split("/")[-1])[0].split("_")[3]
    hand = os.path.splitext(i.split("/")[-1])[0].split("_")[4]
    fing = os.path.splitext(i.split("/")[-1])[0].split("_")[7]
    random_identifier = os.path.splitext(i.split("/")[-1])[0].split("_")[6]
    if fing == '0':
        fing = i.split("/")[-1].split(".")[0].split("_")[1]+"_"+'Index'
    elif fing == '1':
        fing = i.split("/")[-1].split(".")[0].split("_")[1]+"_"+'Middle'
    elif fing == '2':
        fing = i.split("/")[-1].split(".")[0].split("_")[1]+"_"+'Ring'
    elif fing == '3':
        fing = i.split("/")[-1].split(".")[0].split("_")[1]+"_"+'Little'
    if not os.path.exists(os.path.join(dstn_fold,sub_id,sess+"_"+back+"_"+hand+"_"+fing)):
        os.mkdir(os.path.join(dstn_fold,sub_id,sess+"_"+back+"_"+hand+"_"+fing))
    shutil.copy(i,os.path.join(dstn_fold,sub_id,sess+"_"+back+"_"+hand+"_"+fing,random_identifier+'_cl.png'))

f = 0
for i in os.listdir(dstn_fold):
    for j in os.listdir(os.path.join(dstn_fold,i)):
        for j1 in os.listdir(os.path.join(dstn_fold,i,j)):
            f+=1

f=0
for i in tqdm(cb_df['Filename'].tolist()):
    sub_id = os.path.splitext(i.split("/")[-1])[0].split("_")[-3]
    hand = os.path.splitext(i.split("/")[-1])[0].split("_")[-2]
    fing = os.path.splitext(i.split("/")[-1])[0].split("_")[-1]
    sess = os.path.splitext(i.split("/")[-1])[0].split("_")[0]
    ds = os.path.join(dstn_fold,sub_id)
    for j in os.listdir(ds):
        if os.path.exists(os.path.join(ds,j,'cb.png')):
            os.remove(os.path.join(ds,j,'cb.png'))
        if j.split("_")[0] == sess and j.split("_")[2].lower() == hand.lower() and j.split("_")[4] == fing:
            shutil.copy(i,os.path.join(ds,j,'cb.bmp'))
            f+=1

# << ISPFDv1 >>
dstn_fold = "< Path to parent data folder with Black back >"
# dstn_fold = "< Path to parent data folder with Color back >"

f=0
parent_fold = "< Path to cropped dataset >"
# parent_fold = "< Path to cropped dataset >"
# parent_fold = "< Path to cropped dataset >"
# parent_fold = "< Path to cropped dataset >"
for i in tqdm(os.listdir(parent_fold)):
    sub_id = i.split("_")[0]
    fing = i.split("_")[2]
    image_id = i.split("_")[1]
    if not os.path.exists(os.path.join(dstn_fold,sub_id)):
        os.mkdir(os.path.join(dstn_fold,sub_id))
    if not os.path.exists(os.path.join(dstn_fold,sub_id,fing)):
        os.mkdir(os.path.join(dstn_fold,sub_id,fing))
    shutil.copy(os.path.join(parent_fold,i),os.path.join(dstn_fold,sub_id,fing,i.split("_")[1]+i.split("_")[3]+i.split("_")[4]))
    f+=1
print(f)

cb_path = "< Path to Live Scans >"

for i in tqdm(os.listdir(cb_path)):
    sub_id = i.split("_")[0]
    fing = i.split("_")[1]
    sess = i.split("_")[2]
    shutil.copy(os.path.join(cb_path,i),os.path.join(dstn_fold,sub_id,fing,sess+".jpg"))

# <<ISPFD v2>>
dstn_fold = "< Path to parent data folder >"
parent_fold = "< Path to original data folder >"

for i in tqdm(os.listdir(parent_fold)):
    sub_id = i.split("_")[0]
    if not os.path.exists(os.path.join(dstn_fold,sub_id)):
        os.mkdir(os.path.join(dstn_fold,sub_id))
    fing = i.split("_")[1]
    if not os.path.exists(os.path.join(dstn_fold,sub_id,fing)):
        os.mkdir(os.path.join(dstn_fold,sub_id,fing))
    nam = "_".join(i.split("_")[2:])
    shutil.copy(os.path.join(parent_fold,i),os.path.join(dstn_fold,sub_id,fing,nam))

parent_fold = "< Path to original Live Scans folder >"
for i in tqdm(os.listdir(parent_fold)):
    sub_id = i.split("_")[0]
    fing = i.split("_")[1]
    nam = "_".join(i.split("_")[2:])
    shutil.copy(os.path.join(parent_fold,i),os.path.join(dstn_fold,sub_id,fing,nam))

# HKPolyU testing
dstn_fold = "< Path to parent data folder >"

cb_df = pd.read_csv("< csv file for HKPolyU train dataset with CB paths and IDS >")
cl_df = pd.read_csv("< csv file for HKPolyU train dataset with CL paths and IDS >")

subject_id = cb_df['ids'].tolist()
files = cb_df['Filename'].tolist()
for i in tqdm(range(len(subject_id))):
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]))):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i])))
    finger_id = files[i].split('/')[-1].split('.')[0].split('_')[-1]
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]),finger_id)):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i]),finger_id))
    shutil.copy(files[i],os.path.join(dstn_fold,str(subject_id[i]),finger_id,'cb.jpg'))

subject_id = cl_df['ids'].tolist()
files = cl_df['Filename'].tolist()
for i in tqdm(range(len(subject_id))):
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]))):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i])))
    finger_id = files[i].split('/')[-1].split('.')[0].split('_')[-1]
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]),finger_id)):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i]),finger_id))
    shutil.copy(files[i].replace("hkpoly_data/cl", "hkpoly_data/cl_png/cl/").replace(".bmp", ".png"),os.path.join(dstn_fold,str(subject_id[i]),finger_id,'cl.png'))

# HKPolyU validation
dstn_fold = "< Path to parent data folder >"

cb_df = pd.read_csv("< csv file for HKPolyU train dataset with CB paths and IDS >")
cl_df = pd.read_csv("< csv file for HKPolyU train dataset with CL paths and IDS >")

subject_id = cb_df['ids'].tolist()
files = cb_df['Filename'].tolist()
for i in tqdm(range(len(subject_id))):
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]))):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i])))
    finger_id = files[i].split('/')[-1].split('.')[0].split('_')[-1]
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]),finger_id)):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i]),finger_id))
    shutil.copy(files[i],os.path.join(dstn_fold,str(subject_id[i]),finger_id,'cb.jpg'))

subject_id = cl_df['ids'].tolist()
files = cl_df['Filename'].tolist()
for i in tqdm(range(len(subject_id))):
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]))):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i])))
    finger_id = files[i].split('/')[-1].split('.')[0].split('_')[-1]
    if not os.path.exists(os.path.join(dstn_fold,str(subject_id[i]),finger_id)):
        os.mkdir(os.path.join(dstn_fold,str(subject_id[i]),finger_id))
    shutil.copy(files[i].replace("hkpoly_data/cl", "hkpoly_data/cl_png/cl/").replace(".bmp", ".png"),os.path.join(dstn_fold,str(subject_id[i]),finger_id,'cl.png'))