-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove.py
68 lines (50 loc) · 1.35 KB
/
remove.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
# -*- coding: utf-8 -*-
# @Time : 2022/1/19 0019 12:27
# @Author : Xiaofeng
# @FileName: torch[remove]
# @Software: Pycharm
# @Usages :
#将所有文件重新命名
import os
import shutil
import numpy as np
import pandas as pd
image_dir = r'G:\Hospital\case231_revised\ct_liver'
#label_dir = r'F:\EUS\EUS_all\V3\label'
tar_dir = r'G:\Hospital\case231_revised\liver_all'
def pathExist(path):
if not os.path.exists(path):
os.makedirs(path)
return path
pathExist(tar_dir)
excel_dir = r'G:\Hospital\case231_revised\sel.xlsx'
data = pd.read_excel(excel_dir)
data_copy = data.copy()
#data = data.set_index('case')
c1 = data.loc[data['level']==0]
c2 = data.loc[data['level']!=0]
c1_dir = os.path.join(tar_dir,'0')
c2_dir = os.path.join(tar_dir,'1')
pathExist(c1_dir)
pathExist(c2_dir)
# print(c1)
# print(c2)
c1_case = c1['case']
c1_array = np.array(c1_case).tolist()
print(c1_array)
c2_case = c2['case']
c2_array = np.array(c2_case).tolist()
print(c2_array)
for index,ii in enumerate(sorted(os.listdir(image_dir))):
#print(index,ii)
name = int(str(ii.split('.')[0]))
if name in c1_array:
print(name)
ori = os.path.join(image_dir,ii)
print(ori)
shutil.copy(ori, c1_dir)
if name in c2_array:
print(name)
ori = os.path.join(image_dir,ii)
print(ori)
shutil.copy(ori, c2_dir)