def test_reorder(self): (vox_array, affine, aff_trans, ornt_trans) = dcmstack.reorder_voxels(self.vox_array, self.affine, 'PRS') ok_(np.all(vox_array == np.array([[[[4, 5], [6, 7]], [[12, 13], [14,15]] ], [[[0, 1], [2, 3]], [[8, 9], [10, 11]] ] ] ) ) ) ok_(np.allclose(affine, np.array([[0,1,0,0], [-1,0,0,1], [0,0,1,0], [0,0,0,1]]) ) )
def test_no_op(self): vox_order = [dcmstack.closest_ortho_pat_axis(self.affine[:3, idx])[0] for idx in range(3)] vox_order = "".join(vox_order) vox_array, affine, perm = dcmstack.reorder_voxels(self.vox_array, self.affine, vox_order) ok_((vox_array == self.vox_array).all()) ok_((affine == self.affine).all()) eq_(perm, (0, 1, 2)) eq_(np.may_share_memory(affine, self.affine), False)
def test_no_op(self): vox_order = ''.join(aff2axcodes(self.affine)) (vox_array, affine, aff_trans, ornt_trans) = dcmstack.reorder_voxels(self.vox_array, self.affine, vox_order) ok_((vox_array == self.vox_array).all()) ok_((affine == self.affine).all()) ok_((aff_trans == np.eye(4)).all()) ok_(np.allclose(ornt_trans, [[0, 1], [1, 1], [2, 1]])) eq_(np.may_share_memory(affine, self.affine), False)
def test_aniso_reorder(self): self.vox_array = self.vox_array.reshape(2, 4, 2) self.affine = np.eye(4) (vox_array, affine, aff_trans, ornt_trans) = dcmstack.reorder_voxels(self.vox_array, self.affine, 'PLS') ok_( np.allclose( affine, np.array([[0, -1, 0, 1], [-1, 0, 0, 3], [0, 0, 1, 0], [0, 0, 0, 1]])))
def test_no_op(self): vox_order = [ dcmstack.closest_ortho_pat_axis(self.affine[:3, idx])[0] for idx in range(3) ] vox_order = ''.join(vox_order) vox_array, affine, perm = dcmstack.reorder_voxels( self.vox_array, self.affine, vox_order) ok_((vox_array == self.vox_array).all()) ok_((affine == self.affine).all()) eq_(perm, (0, 1, 2)) eq_(np.may_share_memory(affine, self.affine), False)
def test_aniso_reorder(self): self.vox_array = self.vox_array.reshape(2, 4, 2) self.affine = np.eye(4) (vox_array, affine, aff_trans, ornt_trans) = dcmstack.reorder_voxels(self.vox_array, self.affine, 'PLS') ok_(np.allclose(affine, np.array([[0,-1,0,1], [-1,0,0,3], [0,0,1,0], [0,0,0,1]]) ) )
def reorder_voxels(imagedata, qto_xyz, voxel_order): """ Reorder voxel data to the specified voxel_order. Does not directly manipulate imagedata or qto_xyz. Returns manipulated copies of imagedata and qto_xyz. Parameters ---------- imagedata : np.array single np.array of image data qto_xyz : np.matrix, 4x4 patient space voxel_order : str, 3 char 3 character voxel order string, such as 'LPS' or 'RAI' """ log.debug('reorienting to voxel order %s' % voxel_order) new_data, new_qto_xyz, _, _ = dcmstack.reorder_voxels(imagedata, qto_xyz, voxel_order) return new_data, new_qto_xyz
def reorder_voxels(imagedata, qto_xyz, voxel_order): """ Reorder voxel data to the specified voxel_order. Does not directly manipulate imagedata or qto_xyz. Returns manipulated copies of imagedata and qto_xyz. Parameters ---------- imagedata : np.array single np.array of image data qto_xyz : np.matrix, 4x4 patient space voxel_order : str, 3 char 3 character voxel order string, such as 'LPS' or 'RAI' """ log.debug('reorienting to voxel order %s' % voxel_order) new_data, new_qto_xyz, _, _ = dcmstack.reorder_voxels( imagedata, qto_xyz, voxel_order) return new_data, new_qto_xyz