def create_sliceinfo_w(images_fn, labels_fn, regint_fn, kernels, i, slice_no=None): # figure out the biggest slice if slice_no == None: slice_no = find_biggest_slice(path + labels_fn[i]) print("Creating Weighted Slice Info... {}/{}: Slice {}".format( i + 1, len(images_fn), slice_no)) # get the slice, label, and associated orientations slice_im, slice_im_or = get_nifti_slice(path + images_fn[i], slice_no) slice_lb, slice_lb_or = get_nifti_slice(path + labels_fn[i], slice_no) slice_ro, slice_ro_or = get_nifti_slice(path + regint_fn[i], slice_no) # if crop, we crop the image down if crop: crop_x, crop_y = crop start_x = slice_im.shape[0] / 2 - crop_x / 2 end_x = start_x + crop_x start_y = slice_im.shape[1] / 2 - crop_y / 2 end_y = start_y + crop_y slice_im = slice_im[start_x:end_x, start_y:end_y] slice_lb = slice_lb[start_x:end_x, start_y:end_y] slice_ro = slice_ro[start_x:end_x, start_y:end_y] # figure out the principal patches pc_payload = (slice_im, slice_lb) patches_m_pc, patches_n_pc, vals_m, vals_n = create_pc_patches_w( *pc_payload) # compute gabor features for the patches feats_m = [] feats_n = [] intens_m = [] intens_n = [] for patch in patches_m_pc: feats_m.append(compute_feats(patch, kernels)) intens_m.append(compute_intens(patch)) for patch in patches_n_pc: feats_n.append(compute_feats(patch, kernels)) intens_n.append(compute_intens(patch)) # package it into a SliceInfo object si_payload = (images_fn[i], slice_no, slice_im, slice_im_or, slice_lb, slice_lb_or, slice_ro, slice_ro_or, patches_m_pc, patches_n_pc, feats_m, feats_n, intens_m, intens_n, vals_m, vals_n) return SliceInfo(*si_payload)
def create_sliceinfo_w(images_fn, labels_fn, regint_fn, kernels, i, slice_no=None): # figure out the biggest slice if slice_no == None: slice_no = find_biggest_slice(path + labels_fn[i]) print("Creating Weighted Slice Info... {}/{}: Slice {}".format(i+1, len(images_fn), slice_no)) # get the slice, label, and associated orientations slice_im, slice_im_or = get_nifti_slice(path + images_fn[i], slice_no) slice_lb, slice_lb_or = get_nifti_slice(path + labels_fn[i], slice_no) slice_ro, slice_ro_or = get_nifti_slice(path + regint_fn[i], slice_no) # if crop, we crop the image down if crop: crop_x, crop_y = crop start_x = slice_im.shape[0] / 2 - crop_x / 2 end_x = start_x + crop_x start_y = slice_im.shape[1] / 2 - crop_y / 2 end_y = start_y + crop_y slice_im = slice_im[start_x:end_x, start_y:end_y] slice_lb = slice_lb[start_x:end_x, start_y:end_y] slice_ro = slice_ro[start_x:end_x, start_y:end_y] # figure out the principal patches pc_payload = (slice_im, slice_lb) patches_m_pc, patches_n_pc, vals_m, vals_n = create_pc_patches_w(*pc_payload) # compute gabor features for the patches feats_m = [] feats_n = [] intens_m = [] intens_n = [] for patch in patches_m_pc: feats_m.append(compute_feats(patch, kernels)) intens_m.append(compute_intens(patch)) for patch in patches_n_pc: feats_n.append(compute_feats(patch, kernels)) intens_n.append(compute_intens(patch)) # package it into a SliceInfo object si_payload = (images_fn[i], slice_no, slice_im, slice_im_or, slice_lb, slice_lb_or, slice_ro, slice_ro_or, patches_m_pc, patches_n_pc, feats_m, feats_n, intens_m, intens_n, vals_m, vals_n) return SliceInfo(*si_payload)
filenames_label = [] for fn in os.listdir(path): if "CTV" in fn: filenames_label.append(path + fn) else: filenames.append(path + fn) #filenames = [path + "anon_mr_150420_30sec.nii.gz"] #filenames_label = [path + "anon_mr_150420_30sec.nii-label.nrrd.nii.gz"] #slice_no = 128-105 slice_infos = [] for i, fn in enumerate(filenames): slice_no = find_biggest_slice(filenames_label[i]) if DEBUG: print("Processing: ", fn, ", Slice ", slice_no) slice_info = process(fn, filenames_label[i], slice_no) slice_infos.append(slice_info) if REPORTS: for sl in slice_infos: sl.save_report("reports/") else: with open('slice_infos.pkl', 'rb') as f: slice_infos = dill.load(f) #if CLASSIFY: # # we need to go through each slice and collect the masked features and
filenames_label = [] for fn in os.listdir(path): if "CTV" in fn: filenames_label.append(path + fn) else: filenames.append(path + fn) #filenames = [path + "anon_mr_150420_30sec.nii.gz"] #filenames_label = [path + "anon_mr_150420_30sec.nii-label.nrrd.nii.gz"] #slice_no = 128-105 slice_infos = [] for i, fn in enumerate(filenames): slice_no = find_biggest_slice(filenames_label[i]) if DEBUG: print("Processing: ", fn, ", Slice ", slice_no) slice_info = process(fn, filenames_label[i], slice_no) slice_infos.append(slice_info) if REPORTS: for sl in slice_infos: sl.save_report("reports/") else: with open('slice_infos.pkl', 'rb') as f: slice_infos = dill.load(f) if CLASSIFY: # we need to go through each slice and collect the masked features and