Commit 445d587e authored by zhiyang.zhou's avatar zhiyang.zhou

fix a bug of preprocess_data

parent 96e31bcc
...@@ -89,32 +89,33 @@ def preprocess_data(): ...@@ -89,32 +89,33 @@ def preprocess_data():
if os.path.isdir(path): if os.path.isdir(path):
# take image dir and xlsx file # take image dir and xlsx file
sub_paths = os.listdir(path) sub_paths = os.listdir(path)
img_path = None img_paths = []
xlsx_path = None xlsx_path = None
for j in range(0, len(sub_paths)): for j in range(0, len(sub_paths)):
sub_path = os.path.join(path, sub_paths[j]) sub_path = os.path.join(path, sub_paths[j])
if os.path.isdir(sub_path): if os.path.isdir(sub_path):
img_path = sub_path img_paths.append(sub_path)
elif os.path.isfile(sub_path): elif os.path.isfile(sub_path):
xlsx_path = sub_path xlsx_path = sub_path
# take patient info
# take images # take images
processed_dir = './processed-data' for img_path in img_paths:
if not os.path.exists(processed_dir): processed_dir = './processed-data'
os.makedirs(processed_dir) if not os.path.exists(processed_dir):
img_files = os.listdir(img_path) os.makedirs(processed_dir)
img_files = os.listdir(img_path)
for k in range(0, len(img_files)):
img_file = os.path.join(img_path, img_files[k]) for k in range(0, len(img_files)):
img_file_only = img_files[k] img_file = os.path.join(img_path, img_files[k])
islabeled, name, label = check_label(xlsx_path, img_file_only, property=property) img_file_only = img_files[k]
if islabeled and label!=None: islabeled, name, label = check_label(xlsx_path, img_file_only, property=property)
if label >= 8: if islabeled and label!=None:
continue if label >= 8:
tmpstrs = os.path.splitext(img_file_only) continue
dst_img_file_only = tmpstrs[0] + '-' + property + '_' + str(label) + tmpstrs[1] tmpstrs = os.path.splitext(img_file_only)
dst_img_file = os.path.join(processed_dir, dst_img_file_only) dst_img_file_only = tmpstrs[0] + '-' + property + '_' + str(label) + tmpstrs[1]
copyfile(img_file, dst_img_file) dst_img_file = os.path.join(processed_dir, dst_img_file_only)
copyfile(img_file, dst_img_file)
def crop_img(): def crop_img():
from PIL import Image from PIL import Image
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment