def test_get_flexi_tvis_affine(): tvis_hdr = { 'voxel_order': 'RPI', 'dim': (30, 40, 50), 'voxel_size': [2, 3, 4] } grid_affine = np.array([[-2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 4, 0], [0, 0, 0, 1.]]) affine = get_flexi_tvis_affine(tvis_hdr, grid_affine) origin = np.dot(affine, [0, 0, 0, 1]) vsz = np.array(tvis_hdr['voxel_size']) assert_array_almost_equal(origin[:3], np.multiply(tvis_hdr['dim'], vsz) - vsz / 2) # grid_affine = tvis_hdr['voxel_order'] = 'ASL' vsz = tvis_hdr['voxel_size'] = np.array([3, 4, 2.]) affine = get_flexi_tvis_affine(tvis_hdr, grid_affine) vox_point = np.array([9, 8, 7]) trk_point = np.dot(affine, np.append(vox_point, 1)) assert_array_almost_equal(trk_point[:3], (vox_point[[1, 2, 0]] + 0.5) * vsz)
def test_get_flexi_tvis_affine(): tvis_hdr = {'voxel_order': 'RPI', 'dim': (30, 40, 50), 'voxel_size': [2, 3, 4]} grid_affine = np.array([[-2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 4, 0], [0, 0, 0, 1.]]) affine = get_flexi_tvis_affine(tvis_hdr, grid_affine) origin = np.dot(affine, [0, 0, 0, 1]) vsz = np.array(tvis_hdr['voxel_size']) assert_array_almost_equal(origin[:3], np.multiply(tvis_hdr['dim'], vsz) - vsz / 2) # grid_affine = tvis_hdr['voxel_order'] = 'ASL' vsz = tvis_hdr['voxel_size'] = np.array([3, 4, 2.]) affine = get_flexi_tvis_affine(tvis_hdr, grid_affine) vox_point = np.array([9, 8, 7]) trk_point = np.dot(affine, np.append(vox_point, 1)) assert_array_almost_equal(trk_point[:3], (vox_point[[1, 2, 0]] + 0.5) * vsz)