def fileopen(): filename = filedialog.askopenfilename( filetypes=[('numpy files', '*.npy'), ('mhd files', '*.mhd'), ('dicom files', '*.dcm'), ('all', '*')]) #filename = "E:/tianchi_project/TIANCHI_examples/train_1/LKDS-00001.mhd" if filename == '': return print(repr(filename)) prename, extname = os.path.splitext(filename) if extname == '.mhd': full_image_info = sitk.ReadImage(filename) full_scan = sitk.GetArrayFromImage(full_image_info) old_spacing = np.array(full_image_info.GetSpacing())[::-1] volimg, new_spacing = mt.resample(full_scan, old_spacing) elif extname == '.dcm': pathname = os.path.split(filename)[0] full_scan, full_image_info, patientid = mt.read_sph_scan(pathname) #cvm.view_CT(full_scan) old_spacing = np.array(full_image_info.GetSpacing())[::-1] volimg, new_spacing = mt.resample(full_scan, old_spacing) elif extname == '.npy': volimg = np.load(filename) else: print('unknown data type') return label = tk.Label(tool_view, image=cvm.view_CT(volimg)) label.pack() if 'full_scan' in dir(): del full_scan del volimg tool_view.quit()
#ktb.set_session(mt.get_session(0.5)) start_time = time.time() #patient_evaluations = open(evaluation_path + "/patient_evaluations.log", "w") results = [] test_patients = all_patients #test_patients = ["./LUNA16/subset9/1.3.6.1.4.1.14519.5.2.1.6279.6001.195557219224169985110295082004.mhd"] for p in range(len(test_patients)): result = [] patient = test_patients[p] #patient = "./LUNA16/subset9/1.3.6.1.4.1.14519.5.2.1.6279.6001.300270516469599170290456821227.mhd" #patient = "./LUNA16/subset9/1.3.6.1.4.1.14519.5.2.1.6279.6001.212608679077007918190529579976.mhd" #patient = "./LUNA16/subset9/1.3.6.1.4.1.14519.5.2.1.6279.6001.102681962408431413578140925249.mhd" #patient = "./TIANCHI_examples/LKDS-00005.mhd" #uid = mt.get_sample_uid(patient) #annotations = mt.get_luna_annotations(uid, annotation_file) full_scan, full_image_info, uid = mt.read_sph_scan(patient) origin = np.array(full_image_info.GetOrigin())[::-1] old_spacing = np.array(full_image_info.GetSpacing())[::-1] annotations = mt.get_sph_annotations(uid, annotation_file) if len(annotations) == 0: print('%d/%d patient %s has no annotations, ignore it.' % (p + 1, len(test_patients), uid)) #patient_evaluations.write('%d/%d patient %s has no annotations, ignore it\n' %(p+1, len(test_patients), uid)) continue print('%d/%d processing patient:%s' % (p + 1, len(test_patients), uid)) #full_image_info = sitk.ReadImage(patient) #full_scan = sitk.GetArrayFromImage(full_image_info) #origin = np.array(full_image_info.GetOrigin())[::-1] #the order of origin and old_spacing is initially [z,y,x] #old_spacing = np.array(full_image_info.GetSpacing())[::-1] image, new_spacing = mt.resample(full_scan, old_spacing) #resample