forked from afuadhossain/Lung_Cancer_Nodule_Classification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.py
More file actions
53 lines (39 loc) · 1.33 KB
/
Copy pathcleanup.py
File metadata and controls
53 lines (39 loc) · 1.33 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
50
51
52
53
import shutil
import os
import csv
import numpy as np
SUBSET_NUMBER = 0
current_directory = './patches/subset' + str(SUBSET_NUMBER) + '/benign/'
cancer_directory = './patches/subset' + str(SUBSET_NUMBER) + '/cancer/'
def readCSV(filename):
lines = []
with open(filename, "rb") as f:
csvreader = csv.reader(f)
for line in csvreader:
lines.append(line)
return lines
cands = readCSV('./data/candidates.csv')
def find_cancer():
cancer_set = set()
for cand in cands:
if (cand[4] == '1'):
worldCoord = np.asarray([float(cand[3]), float(cand[2]), float(cand[1])])
candidate_name = 'patch_' + str(worldCoord[0]) + '_' + str(worldCoord[1]) + '_' + str(worldCoord[2]) + '.png'
cancer_set.add(candidate_name)
return cancer_set
def main():
#Finds Images that have cancer and moves them
cancer_set = find_cancer()
total_count = 0
cancer_count = 0
for filename in os.listdir(current_directory):
#print(filename)
total_count += 1
if filename in cancer_set:
shutil.move(current_directory + filename, cancer_directory + str(SUBSET_NUMBER) + '_' + filename[:-4] + '_C' + '.png')
cancer_count+=1
else:
shutil.move(current_directory + filename, current_directory + str(SUBSET_NUMBER) + '_' + filename)
print ('Total Count: {} Cancer Count: {}'.format(total_count, cancer_count))
if __name__ == '__main__':
main()