-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPH2_data_extraction.py
54 lines (45 loc) · 1.72 KB
/
PH2_data_extraction.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
# importing libs
import os
import shutil
import csv
def main():
# removing old data and creating new directories
if os.path.exists(os.getcwd() + "/Data"):
shutil.rmtree(os.getcwd() + "/Data")
os.makedirs(os.getcwd() + "/Data")
os.makedirs(os.getcwd() + "/Data/melanoma")
os.makedirs(os.getcwd() + "/Data/nevus")
# reading from .csv file
class_path = os.getcwd() + "/PH2_dataset.csv"
with open(class_path) as classification:
classification_reader = csv.reader(classification, delimiter=',')
line_count = 0
mel_count = 0
nev_count = 0
for row in classification_reader:
# Skipping 1st 13 lines
if line_count < 13:
line_count += 1
continue
else:
print(">>> " + row[0])
type = row[4]
if type is "X":
dst = os.getcwd() + "/Data/melanoma"
print("Melanoma Entry")
mel_count += 1
else:
dst = os.getcwd() + "/Data/nevus"
print("Nevus Entry")
nev_count += 1
src = os.getcwd() + "/PH2 Dataset images/" + row[0] + "/" + row[0] + "_Dermoscopic_Image/" \
+ row[0] + ".bmp"
shutil.copy(src, dst)
line_count += 1
print("Melanoma Count: " + str(mel_count))
print("Nevus Count: " + str(nev_count))
print("------------------------------------")
#######################################################################################################################
# Main Call Func. >>>
if __name__ == "__main__":
main()