def sanity_check(): subject = 'mg101' template_system = 'hc029' # mg101 RMF3 to hc029 tk_ras = [7.3, 37.9, 59] ras = [6.08, 73.07, 17.80] vox = [121, 69, 166] template_tk_ras_true = np.array([6.18, 52.26, 21.46]) template_vox_true = np.array([122, 107, 180]) template_tk_ras, trans = fu.transform_subject_to_subject_coordinates( subject, template_system, tk_ras, SUBJECTS_DIR, return_trans=True) template_tk_ras2 = apply_trans(trans, tk_ras) assert (all(np.isclose(template_tk_ras, template_tk_ras2, rtol=1e-3))) lta = fu.read_lta_file( op.join(SUBJECTS_DIR, subject, 'mri', 't1_to_{}.lta'.format(template_system))) lta[np.isclose(trans, np.zeros(lta.shape))] = 0 print(lta - trans) # template_lta_tk_ras = lta_transfer_ras2ras(subject, tk_ras) # assert(all(np.isclose(template_tk_ras_true, template_tk_ras, rtol=1e-3))) subject = 'mg112' # ROF1 - 2 tk_ras = [2.00, 29.00, 8.00] ras = [-6.88, 50.40, -7.31] template_tk_ras = fu.transform_subject_to_subject_coordinates( subject, template_system, tk_ras, SUBJECTS_DIR) print('asdf')
def lta_transfer_vox2vox(subject, coords): lta_fname = op.join(SUBJECTS_DIR, subject, 'mri', 't1_to_{}_vox2vox.lta'.format(template_system)) if not op.isfile(lta_fname): return None lta = fu.read_lta_file(lta_fname) subject_header = nib.load(op.join(SUBJECTS_DIR, subject, 'mri', 'T1.mgz')).get_header() template_header = nib.load( op.join(SUBJECTS_DIR, template_system, 'mri', 'T1.mgz')).get_header() vox = apply_trans(np.linalg.inv(subject_header.get_vox2ras_tkr()), coords) template_vox = apply_trans(lta, vox) template_cords = apply_trans(template_header.get_vox2ras_tkr(), template_vox) return template_cords
def lta_transfer_ras2ras(subject, coords, return_trans=False): lta_fname = op.join(SUBJECTS_DIR, subject, 'mri', 't1_to_{}.lta'.format(template_system)) if not op.isfile(lta_fname): return None lta = fu.read_lta_file(lta_fname) lta[np.isclose(lta, np.zeros(lta.shape))] = 0 subject_header = nib.load(op.join(SUBJECTS_DIR, subject, 'mri', 'T1.mgz')).get_header() template_header = nib.load( op.join(SUBJECTS_DIR, template_system, 'mri', 'T1.mgz')).get_header() vox = apply_trans(np.linalg.inv(subject_header.get_vox2ras_tkr()), coords) ras = apply_trans(subject_header.get_vox2ras(), vox) template_ras = apply_trans(lta, ras) template_vox = apply_trans(template_header.get_ras2vox(), template_ras) template_cords = apply_trans(template_header.get_vox2ras_tkr(), template_vox) if return_trans: return template_cords, lta else: return template_cords