def filter_vols(): cr_vol = nib.load(pat.get_path('crop')).get_data() if len(cr_vol.shape) == 4: cr_vol = cr_vol[..., 0] borders_vol = np.where(cr_vol == 1) x_fr, y_fr, z_fr = map(np.min, borders_vol) x_to, y_to, z_to = map(np.max, borders_vol) print x_fr, y_fr, z_fr, x_to, y_to, z_to for p, d, f in os.walk(pat.get_path('separated')): for fname in f: INTENSITY_SIGMA = 40 GAUSSIAN_SIGMA = 1.5 nii_separator.set_header_from(os.path.join(p, fname), '/home/denest/PERF_volumes/ZAKHAROVA O.A. 13.11.1981/20140610_635/NII/SEPARATED/s004a001_3.nii.gz') if not os.path.isfile(os.path.join(pat.get_path('filtered'), '%s_I%s_G%s.nii' % ( fname.rstrip('.nii.gz'), INTENSITY_SIGMA, GAUSSIAN_SIGMA))): bilateral.bilateral(os.path.join(p, fname), output_folder=pat.get_path('filtered'), sig_i=INTENSITY_SIGMA, sig_g=GAUSSIAN_SIGMA, x_range=[x_fr, x_to], y_range=[y_fr, y_to], z_range=[z_fr, z_to]) else: print 'exists', os.path.join(pat.get_path('filtered'), '%s_I%s_G%s.nii' % ( fname.rstrip('.nii.gz'), INTENSITY_SIGMA, GAUSSIAN_SIGMA)) for fn in pat.files_in('filtered'): splited_fname = re.split(r"s|a|_", fn) print splited_fname s, a = [int(i) for i in (splited_fname[1], splited_fname[3])] pat.add_path(fn, 'filtered', s, a, add_to=(pat.get_path('filtered')))
def filter_vols(): for p, d, f in os.walk(pat.get_path('separated')): for fname in f: INTENSITY_SIGMA = 40 GAUSSIAN_SIGMA = 1.5 if not os.path.isfile(os.path.join(pat.get_path('filtered'), '%s_I%s_G%s.nii' % ( fname.rstrip('.nii.gz'), INTENSITY_SIGMA, GAUSSIAN_SIGMA))): print os.path.join(pat.get_path('filtered'), '%s_I%s_G%s.nii' % (fname.rstrip('.nii.gz'), INTENSITY_SIGMA, GAUSSIAN_SIGMA)) bilateral.bilateral(os.path.join(p, fname), output_folder=pat.get_path('filtered'), sig_i=INTENSITY_SIGMA, sig_g=GAUSSIAN_SIGMA, x_range=[x_fr, x_to], y_range=[y_fr, y_to], z_range=[z_fr, z_to]) else: print 'exists', os.path.join(pat.get_path('filtered'), '%s_I%s_G%s.nii' % ( fname.rstrip('.nii.gz'), INTENSITY_SIGMA, GAUSSIAN_SIGMA))
def filter_vols(): cr_vol = nib.load(pat.get_path('crop')).get_data() if len(cr_vol.shape) == 4: cr_vol = cr_vol[..., 0] borders_vol = np.where(cr_vol == 1) x_fr, y_fr, z_fr = map(np.min, borders_vol) x_to, y_to, z_to = map(np.max, borders_vol) print x_fr, y_fr, z_fr, x_to, y_to, z_to for p, d, f in os.walk(pat.get_path('separated')): for fname in f: INTENSITY_SIGMA = 40 GAUSSIAN_SIGMA = 1.5 nii_separator.set_header_from( os.path.join(p, fname), '/home/denest/PERF_volumes/ZAKHAROVA O.A. 13.11.1981/20140610_635/NII/SEPARATED/s004a001_3.nii.gz' ) if not os.path.isfile( os.path.join( pat.get_path('filtered'), '%s_I%s_G%s.nii' % (fname.rstrip('.nii.gz'), INTENSITY_SIGMA, GAUSSIAN_SIGMA))): bilateral.bilateral(os.path.join(p, fname), output_folder=pat.get_path('filtered'), sig_i=INTENSITY_SIGMA, sig_g=GAUSSIAN_SIGMA, x_range=[x_fr, x_to], y_range=[y_fr, y_to], z_range=[z_fr, z_to]) else: print 'exists', os.path.join( pat.get_path('filtered'), '%s_I%s_G%s.nii' % (fname.rstrip('.nii.gz'), INTENSITY_SIGMA, GAUSSIAN_SIGMA)) for fn in pat.files_in('filtered'): splited_fname = re.split(r"s|a|_", fn) print splited_fname s, a = [int(i) for i in (splited_fname[1], splited_fname[3])] pat.add_path(fn, 'filtered', s, a, add_to=(pat.get_path('filtered')))
def filter_vols(self, intensity_sigma=40, gaussian_sigma=1.5): cr_vol = nib.load(self.dir_manager.get_path('crop')).get_data() if len(cr_vol.shape) == 4: cr_vol = cr_vol[..., 0] borders_vol = np.where(cr_vol == 1) x_fr, y_fr, z_fr = map(np.min, borders_vol) x_to, y_to, z_to = map(np.max, borders_vol) for p, d, f in os.walk(self.dir_manager.get_path('separated')): for fname in f: if not os.path.isfile(os.path.join(self.dir_manager.get_path('filtered'), '%s_I%s_G%s.nii' % ( fname.rstrip('.nii.gz'), intensity_sigma, gaussian_sigma))): # nii_separator.set_header_from(os.path.join(p, fname), # '/home/denest/PERF_volumes/ZAKHAROVA O.A. 13.11.1981/20140610_635/NII/SEPARATED/s004a001_3.nii.gz') bilateral.bilateral(os.path.join(p, fname), output_folder=self.dir_manager.get_path('filtered'), sig_i=intensity_sigma, sig_g=gaussian_sigma, x_range=[x_fr, x_to], y_range=[y_fr, y_to], z_range=[z_fr, z_to]) else: print 'exists', os.path.join(self.dir_manager.get_path('filtered'), '%s_I%s_G%s.nii' % ( fname.rstrip('.nii.gz'), intensity_sigma, gaussian_sigma))
def filter_vols(): for p, d, f in os.walk(pat.get_path('separated')): for fname in f: INTENSITY_SIGMA = 40 GAUSSIAN_SIGMA = 1.5 if not os.path.isfile( os.path.join( pat.get_path('filtered'), '%s_I%s_G%s.nii' % (fname.rstrip('.nii.gz'), INTENSITY_SIGMA, GAUSSIAN_SIGMA))): print os.path.join( pat.get_path('filtered'), '%s_I%s_G%s.nii' % (fname.rstrip('.nii.gz'), INTENSITY_SIGMA, GAUSSIAN_SIGMA)) bilateral.bilateral(os.path.join(p, fname), output_folder=pat.get_path('filtered'), sig_i=INTENSITY_SIGMA, sig_g=GAUSSIAN_SIGMA, x_range=[x_fr, x_to], y_range=[y_fr, y_to], z_range=[z_fr, z_to]) else: print 'exists', os.path.join( pat.get_path('filtered'), '%s_I%s_G%s.nii' % (fname.rstrip('.nii.gz'), INTENSITY_SIGMA, GAUSSIAN_SIGMA))
for p, d, f in os.walk(self.dir_manager.get_path('separated')): for fname in f: if not os.path.isfile( os.path.join( self.dir_manager.get_path('filtered'), '%s_I%s_G%s.nii' % (fname.rstrip('.nii.gz'), intensity_sigma, gaussian_sigma))): # nii_separator.set_header_from(os.path.join(p, fname), # '/home/denest/PERF_volumes/ZAKHAROVA O.A. 13.11.1981/20140610_635/NII/SEPARATED/s004a001_3.nii.gz') bilateral.bilateral( os.path.join(p, fname), output_folder=self.dir_manager.get_path('filtered'), sig_i=intensity_sigma, sig_g=gaussian_sigma, x_range=[x_fr, x_to], y_range=[y_fr, y_to], z_range=[z_fr, z_to]) else: print 'exists', os.path.join( self.dir_manager.get_path('filtered'), '%s_I%s_G%s.nii' % (fname.rstrip('.nii.gz'), intensity_sigma, gaussian_sigma)) def registration_start(self, target_phase, phase_exclusion=()): ants = self.ants # registration def registration(moved_image, fixed_image, mask, output_folder):
def RSE(m, r): return math.sqrt(np.square(m - r).sum()) filename = str(input()).rstrip() img = imageio.imread(filename).astype(np.float) method = int(input()) save = int(input()) if method == 1: n = int(input()) sigma_s = float(input()) sigma_r = float(input()) output_img = bilateral(img, n, sigma_s, sigma_r) elif method == 2: c = float(input()) k = int(input()) output_img = unsharp(img, c, k) elif method == 3: sigma_row = float(input()) sigma_col = float(input()) output_img = vinagrette(img, sigma_row, sigma_col) else: raise Exception("Method " + str(method) + " unimplemented") output_img = output_img.astype(np.uint8) print("{0:.4f}".format(RSE(output_img, img)))
except IOError,s: print 'no crop volume',s x_fr, y_fr, z_fr = (None,None,None) x_to, y_to, z_to = (None,None,None) for p, d, f in os.walk(self.dir_manager.get_path('separated')): for fname in f: if not os.path.isfile(os.path.join(self.dir_manager.get_path('filtered'), '%s_I%s_G%s.nii' % ( fname.rstrip('.nii.gz'), intensity_sigma, gaussian_sigma))): # nii_separator.set_header_from(os.path.join(p, fname), # '/home/denest/PERF_volumes/ZAKHAROVA O.A. 13.11.1981/20140610_635/NII/SEPARATED/s004a001_3.nii.gz') bilateral.bilateral(os.path.join(p, fname), output_folder=self.dir_manager.get_path('filtered'), sig_i=intensity_sigma, sig_g=gaussian_sigma, x_range=[x_fr, x_to], y_range=[y_fr, y_to], z_range=[z_fr, z_to]) else: print 'exists', os.path.join(self.dir_manager.get_path('filtered'), '%s_I%s_G%s.nii' % ( fname.rstrip('.nii.gz'), intensity_sigma, gaussian_sigma)) def registration_start(self, target_phase, phase_exclusion=()): ants = self.ants # registration def registration(moved_image, fixed_image, mask, output_folder): prefix = '%s_to_%s' % ( os.path.basename(moved_image).split('.')[0], os.path.basename(fixed_image).split('.')[0])