# predict dir root_dir = '/media/louis/Volume/ProgramWorkResult/MICCAI_2017_6_12/Result_Eigenfaces_KNN/RegPatchedImage' if OrganPatch == True: result_dir_pre = root_dir + '/'+organ + '/PCA_predict' elif LocalPatach == True: result_dir_pre = root_dir + '/'+organ + 'LocalPatch'+ '/PCA_predict' else: raise ValueError('please choose the patch pattern') print 'Results will be stored in:', result_dir_pre if not os.path.exists(result_dir_pre): subprocess.call('mkdir ' + '-p ' + result_dir_pre, shell=True) #--------------- -------------------------------------------------------------- im_fns = Dpp.readTxtIntoList(result_dir_pre + '/' + 'FileList.txt') predict_list = Dpp.ImageModificationAfterTransform(im_fns, result_dir_pre, constraintPredict) # ground truth dir root_dir = '/media/louis/Volume/ProgramWorkResult/MICCAI_2017_6_12/Result_Eigenfaces_KNN/RegPatchedImage' if OrganPatch == True: result_dir_true = root_dir + '/'+organ + '/PCA_test' elif LocalPatach == True: result_dir_true = root_dir + '/'+organ + 'LocalPatch'+ '/PCA_test' else: raise ValueError('please choose the patch pattern') if not os.path.exists(result_dir_true): subprocess.call('mkdir ' + '-p ' + result_dir_true, shell=True)
print 'Results will be stored in:', result_dir if not os.path.exists(result_dir): subprocess.call('mkdir ' + '-p ' + result_dir, shell=True) outputPrefix = os.path.join(result_dir, 'JLF_predict/') if not os.path.exists(outputPrefix): subprocess.call('mkdir ' + '-p ' + outputPrefix, shell=True) # For reproducibility: save all parameters into the result dir currentPyFile = os.path.realpath(__file__) os.system('cp ' + currentPyFile + ' ' + result_dir) #%% X_data_dir = root_image_dir + '/' + organ + '_' + regIfLinear + '_Imagepatch' Y_data_dir = root_label_dir + '/' + organ + '_' + regIfLinear + '_Labelpatch' X_data_list = Dpp.readTxtIntoList(X_data_dir + '/FileList.txt') Y_data_list = Dpp.readTxtIntoList(Y_data_dir + '/FileList.txt') reference_im_fn = X_data_list[0] # lamada: the tunning paramter that weights between the low-rank component and the sparse component global lamda lamda = 0.7 tol = 1e-07 # train data and test data data_num = len(X_data_list) PcNo = data_num - 1 MonteTime = 1 best_k = 30 #%%
TPR_Statistics['max'] = np.amax(TPR) TPR_Statistics['min'] = np.amin(TPR) print 'TPF' print TPR_Statistics #%% # predict dir root_dir = '/media/data/louis/ProgramWorkResult/VisercialMAS_ANT/Result_Eigenfaces_KNN/PatchedImage' result_dir_pre = root_dir + '/' + organ + '_' + regIfLinear + '/JLF_predict' if not os.path.exists(result_dir_pre): subprocess.call('mkdir ' + '-p ' + result_dir_pre, shell=True) #-------------------------------------------------------------------------- im_fns = Dpp.readTxtIntoList(result_dir_pre + '/' + 'FileList.txt') predict_list = Dpp.ImageModificationAfterTransform(im_fns, result_dir_pre, constraintPredict) RegOutput_dir = root_dir + '/' + organ + '_' + regIfLinear + '/JLF_predict' Dpp.WriteListtoFile(predict_list, RegOutput_dir + "/FileListZoom.txt") # ground truth dir root_dir = '/media/data/louis/ProgramWorkResult/VisercialMAS_ANT/Result_Eigenfaces_KNN/PatchedImage' result_dir_true = root_dir + '/' + organ + '_' + regIfLinear + '/PCA_test' if not os.path.exists(result_dir_true): subprocess.call('mkdir ' + '-p ' + result_dir_true, shell=True) #-------------------------------------------------------------------------- im_fns = Dpp.readTxtIntoList(result_dir_true + '/' + 'FileList.txt') groundTruth_list = Dpp.ImageModificationAfterTransform(im_fns, result_dir_true,
#%% root_dir = '/media/data/louis/ProgramWorkResult/VisercialMAS_ANT' Input_Root_dir = root_dir + '/Patched_Image' Image_Root_Dir = Input_Root_dir + '/GC_Volumes_patch_Elastix/' + organ + '_ImageMask' Label_Root_Dir = Input_Root_dir + '/GC_label_patch_Elastix/' + organ + '_LabelMask' Output_Root_dir = '/media/louis/Volume/ProgramWorkResult/MICCAI_2017_6_12/OrganReg_Elastix' Image_Result_Dir = Output_Root_dir + '/Volume_OrganReg' + '/' + organ Label_Result_Dir = Output_Root_dir + '/Label_OrganReg' + '/' + organ # Make reference reference_dir = root_dir + '/Full_Image/GC_Volumes_adjustment' + '/referenceImage' selName = "10000128_1_CTce_ThAb" DirFile = Dpp.readTxtIntoList(Image_Root_Dir + '/FileList.txt') for dir_i in DirFile: if dir_i.find(selName) != -1: referenceImageMask = dir_i break #%% # Registration if IFNormalization != False: reference_im_fn = reference_dir + '/reference_WithNorm' + '.nrrd' else: reference_im_fn = reference_dir + '/reference_WithoutNorm' + '.nrrd' Imagereginput_dir = Image_Root_Dir images = Dpp.readTxtIntoList(Imagereginput_dir + '/InputImageList.txt') iamges_mask = Dpp.readTxtIntoList(Imagereginput_dir + '/FileList.txt') ImageRegOutput_dir = Image_Result_Dir
reference_im_fn = reference_dir + '/reference_WithoutNorm' + '.nrrd' #------------------------------------------------------------------------------ Regmode = 'linear' #Regmode = 'nonlinear' #organ = '40358_muscle_body_of_left_rectus_abdominis' #organ = '187_gallbladder' #organ = '170_pancreas' #organ = '30325_left_adrenal_gland' #organ = '30324_right_adrenal_gland' organ = '29193_first_lumbar_vertebra' #''' # %% # adjust the original Label data. data_folder = '/media/louis/Volume/ResearchData/visceral_used/GC_Labels/' + organ im_fns = Dpp.readTxtIntoList(data_folder + '/FileList.txt') searchName = "10000129_1_CTce_ThAb" for dir_i in im_fns: if dir_i.find(searchName) != -1: im_fns.remove(dir_i) break label_dir = root_label_dir + '/' + organ sizeadjust_label_dir = label_dir + '/sizeadjustment' if not os.path.exists(sizeadjust_label_dir): subprocess.call('mkdir ' + '-p ' + sizeadjust_label_dir, shell=True) cuttingresult_dir = label_dir + '/cuttingresult' if not os.path.exists(cuttingresult_dir): subprocess.call('mkdir ' + '-p ' + cuttingresult_dir, shell=True)
# show image information import SimpleITK as sitk # SimpleITK to load images import sys sys.path.insert(0, '../') import DataPreProcessing.Func_data_preprocessing as Dpp #%% data_folder = '/media/louis/Volume/ProgramWorkResult/MICCAI_2017_6_12/Full_Image/GC_Volumes_adjustment/cuttingresult' InputImageList = Dpp.readTxtIntoList(data_folder + '/FileList.txt') for i in xrange(len(InputImageList)): image = sitk.ReadImage(InputImageList[i]) image_array = sitk.GetArrayFromImage(image) # get numpy array print 'Image No. %d' % (i) print 'dim z,x,y :' + str(image_array.shape) print 'Origin:' + str(image.GetOrigin()) print 'sapcing:' + str(image.GetSpacing())
import os import subprocess sys.path.insert(0, '../') import DataPreProcessing.Func_data_preprocessing as Dpp regIfLinear = "Linear" #regIfLinear = "nonlinear" organ = '187_gallbladder' #organ = '170_pancreas' #organ = '30325_left_adrenal_gland' #organ = '30324_right_adrenal_gland' #organ = '29193_first_lumbar_vertebra' root_dir = '/media/louis/Volume/ProgramWorkResult/VisercialMAS_ANT' label_data_dir = root_dir + '/Full_Image/GC_label_adjustment' + '/'+organ +\ '/Regtrans_' + regIfLinear +'_ANT' result_dir_lab = root_dir + '/Full_Image/GC_label_adjustment' + '/'+organ +\ '/Modification_Regtrans_' + regIfLinear + '_ANT' print 'Results will be stored in:', result_dir_lab if not os.path.exists(result_dir_lab): subprocess.call('mkdir ' + '-p ' + result_dir_lab, shell=True) #-------------------------------------------------------------------------------- im_fns_label = Dpp.readTxtIntoList(label_data_dir + '/FileList.txt') result_lab_list = Dpp.ImageModificationAfterTransform(im_fns_label, result_dir_lab) Dpp.WriteListtoFile(result_lab_list, result_dir_lab + '/FileList.txt')
root_dir = '/media/data/louis/ProgramWorkResult/VisercialMAS_ANT' reference_dir = root_dir + '/Full_Image' + '/GC_Volumes_adjustment/referenceImage' reference_im_fn = reference_dir + '/reference_WithoutNorm' + '.nrrd' #%% # patching images regIfLinear = "Linear" organ = '187_gallbladder' factor = 4.0 label_data_dir = root_dir + '/Full_Image' + '/GC_label_adjustment'+'/'+organ +\ '/Modification_Regtrans_' + regIfLinear + '_ANT' iamge_data_dir = root_dir + '/Full_Image' + '/GC_Volumes_adjustment/Regtrans_' +\ regIfLinear + '_ANT' im_fns_label = Dpp.readTxtIntoList(label_data_dir + '/FileList.txt') im_fns = Dpp.readTxtIntoList(iamge_data_dir + '/FileList.txt') imname, imext = os.path.splitext(im_fns[0]) imageNameList = imname.split("_")[0:-4] im_fns_image = [] for i in xrange(len(im_fns_label)): name, ext = os.path.splitext(im_fns_label[i]) labelBaseName = os.path.basename(name) imageBaseName = string.join( imageNameList + labelBaseName.split("_")[-6:-2], "_") im_fns_image.append(imageBaseName + imext) image_result_dir = root_dir + '/Patched_Image/GC_Volumes_patch' + '_ANT' label_result_dir = root_dir + '/Patched_Image/GC_label_patch' + '_ANT' result_dir_img = image_result_dir + '/' + organ + '_ImageMask'