def __init__(self, image, control_points, sigma, grid_coords=False, affine=None): """ control_points: a Nx3 array of world coordinates if grid_coords is True, both `control_points` and `sigma` are interpreted in voxel coordinates. """ nparams = np.prod(control_points.shape) self._generic_init(image, affine, nparams) fromworld = inverse_affine(self._toworld) if grid_coords: self._control_points = apply_affine(self._toworld, control_points) tmp = control_points else: self._control_points = np.asarray(control_points) tmp = apply_affine(fromworld, control_points) # TODO : make sure the control point indices fall within the # subgrid and maybe raise a warning if rounding is too severe tmp = np.round(tmp).astype('int') self._idx_control_points = tuple([tmp[:,:,:,i] for i in range(tmp.shape[3])]) self._sigma = sigma*np.ones(3) self._grid_sigma = np.abs(np.diagonal(fromworld)[0:-1]*sigma) self._norma = np.prod(np.sqrt(2*np.pi)*self._grid_sigma)
def test_apply_affine(): XYZ = (100*(np.random.rand(10,11,12,3)-.5)).astype('int') T = np.eye(4) T[0:3,0:3] = np.random.rand(3,3) T[0:3,3] = 100*(np.random.rand(3)-.5) _XYZ = apply_affine(inverse_affine(T), apply_affine(T, XYZ)) assert_almost_equal(_XYZ, XYZ)