def __init__(self, input_dictionary): """Initialize image level tools""" # initialize all the model objects self.dc = data_container(input_dictionary['image_data'], input_dictionary['times'], input_dictionary) self._t = transformer.transformer() self._m = matcher.matcher(input_dictionary['matcher'], input_dictionary['window']) self._r = regularizer.regularizer(input_dictionary['regularizer'], input_dictionary['abcd'][0], input_dictionary['abcd'][1], input_dictionary['abcd'][2], input_dictionary['abcd'][3], self.dc.curr_vox, self.dc.curr_res)
""" import sys import numpy as np import nibabel as nib import pyrpl.image_tools.transformer as transformer # get file paths img_root = sys.argv[1] txm_root = sys.argv[2] wPath = sys.argv[3] # image details, transformer for later sh = (220, 220, 220) vox = np.array([1., 1., 1.]) _t = transformer.transformer() # grab the data img = nib.load(img_root).get_data().squeeze() # grab the transformation to mdt coordinates txm = np.empty(sh + (3, )) for i in range(3): p = txm_root + str(i) + '.nii.gz' txm[..., i] = nib.load(p).get_data().squeeze() # Apply txm to data img = _t.apply_transform(img, vox, txm) # save results img = nib.Nifti1Image(img, np.eye(4))
def main(): # grab the input parameters reference_path = sys.argv[1] write_path_root = sys.argv[2] outer_iterations = int(sys.argv[3]) # get the reference image, make an id string for it ref = nib.load(reference_path).get_data().squeeze() #ref = preproc.rescale_intensity(ref, mean=1.0) # currently assumes filenames are unique between inputs # consider generating a unique hash here, common suffix between references ref_str = reference_path.split('/')[-1].split('.')[0] # create transformer for later _t = transformer.transformer() # establish parameters for registration of template to reference params = { 'vox': np.array([1.0, 1.0, 1.0]), 'oIts': outer_iterations, 'pStep': 1e-5, 'iStep': 0.0, 'tStep': 1.0, 'rat': 1.0, 'its': [5], 'res': [ref.shape], 'h': 8, 'a': 1.0, 'b': 0.0, 'c': 0.05, 'd': 2.0, 'mType': 'SSD', 'rType': 'differential' } # number of template updates for o in range(outer_iterations): # keep cycling until the newest template is done tPath = write_path_root + '/template' + str(o) + '.nii.gz' tFound = False while not tFound: if os.path.exists(tPath): time.sleep(5) tFound = True tmp = nib.load(tPath).get_data().squeeze() # tmp = preproc.rescale_intensity(tmp, mean=1.0) else: time.sleep(2) # Register the template to the reference image J = np.array([tmp, ref]) T = np.array([0.0, 1.0]) # Fit geodesic grdc, P0_mag, data_match, grad_mag = optimizer.optimize(J, T, params) # write out the momentum and transformations wPath = write_path_root + '/' + ref_str + '_momentum.npy' np.save(wPath, grdc.P[0]) I0 = _t.apply_transform(ref, grdc.full_vox, grdc.uf[-1]) wPath = write_path_root + '/' + ref_str + '_I0.npy' np.save(wPath, I0)