本文整理汇总了Python中nipy.core.api.AffineTransform.renamed_domain方法的典型用法代码示例。如果您正苦于以下问题:Python AffineTransform.renamed_domain方法的具体用法?Python AffineTransform.renamed_domain怎么用?Python AffineTransform.renamed_domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nipy.core.api.AffineTransform
的用法示例。
在下文中一共展示了AffineTransform.renamed_domain方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ni_affine_pixdim_from_affine
# 需要导入模块: from nipy.core.api import AffineTransform [as 别名]
# 或者: from nipy.core.api.AffineTransform import renamed_domain [as 别名]
def ni_affine_pixdim_from_affine(affine_transform, strict=False):
"""
Given a square affine_transform,
return a new 3-dimensional AffineTransform
and the pixel dimensions in dimensions
greater than 3.
If strict is True, then an exception is raised if
the affine matrix is not diagonal with
positive entries in dimensions
greater than 3.
If strict is True, then the names of the range coordinates
must be LPS:('x+LR','y+PA','z+SI') or RAS:('x+RL','y+AP','z+SI'). If strict is False, and the names
are not either of these, LPS:('x+LR','y+PA','z+SI') are used.
If the names are RAS:('x+RL','y+AA','z+SI'), then the affine is flipped
so the result is in LPS:('x+LR','y+PA','z+SI').
NIFTI images have the first 3 dimensions as spatial, and the
remaining as non-spatial, with the 4th typically being time.
Parameters
----------
affine_transform : `AffineTransform`
Returns
-------
nifti_transform: `AffineTransform`
A 3-dimensional or less AffineTransform
pixdim : ndarray(np.float)
The pixel dimensions greater than 3.
>>> outnames = CS(('x+LR','y+PA','z+SI') + ('t',))
>>> innames = CS(['phase', 'j', 'frequency', 't'])
>>> af_tr = AT(outnames, innames, np.diag([2,-2,3,3.5,1]))
>>> print af_tr
AffineTransform(
function_domain=CoordinateSystem(coord_names=('x+LR', 'y+PA', 'z+SI', 't'), name='', coord_dtype=float64),
function_range=CoordinateSystem(coord_names=('phase', 'j', 'frequency', 't'), name='', coord_dtype=float64),
affine=array([[ 2. , 0. , 0. , 0. , 0. ],
[ 0. , -2. , 0. , 0. , 0. ],
[ 0. , 0. , 3. , 0. , 0. ],
[ 0. , 0. , 0. , 3.5, 0. ],
[ 0. , 0. , 0. , 0. , 1. ]])
)
>>> af_tr3dorless, p = ni_affine_pixdim_from_affine(af_tr)
>>> print af_tr3dorless
AffineTransform(
function_domain=CoordinateSystem(coord_names=('x+LR', 'y+PA', 'z+SI'), name='', coord_dtype=float64),
function_range=CoordinateSystem(coord_names=('x+LR', 'y+PA', 'z+SI'), name='', coord_dtype=float64),
affine=array([[ 2., 0., 0., 0.],
[ 0., -2., 0., 0.],
[ 0., 0., 3., 0.],
[ 0., 0., 0., 1.]])
)
>>> print p
[ 3.5]
"""
if ((not isinstance(affine_transform, AT)) or
(affine_transform.ndims[0] != affine_transform.ndims[1])):
raise ValueError('affine_transform must be a square AffineTransform' +
' to save as a NIFTI file')
ndim = affine_transform.ndims[0]
ndim3 = min(ndim, 3)
range_names = affine_transform.function_range.coord_names
if range_names[:ndim3] not in [lps_output_coordnames[:ndim3],
ras_output_coordnames[:ndim3]]:
if strict:
raise ValueError('strict is true and the range is not LPS or RAS, assuming LPS')
warnings.warn('range is not LPS or RAS, assuming LPS')
range_names = list(range_names)
range_names[:ndim3] = lps_output_coordnames[:ndim3]
range_names = tuple(range_names)
ndim = affine_transform.ndims[0]
nifti_indim = 'ijk'[:ndim] + 'tuvw'[ndim3:ndim]
nifti_outdim = range_names[:ndim3] + \
('t', 'u', 'v', 'w' )[ndim3:ndim]
nifti_transform = AT(CS(nifti_indim),
CS(nifti_outdim),
affine_transform.affine)
domain_names = affine_transform.function_domain.coord_names[:ndim3]
nifti_transform = nifti_transform.renamed_domain(dict(zip('ijk'[:ndim3],
domain_names)))
# now find the pixdims
A = nifti_transform.affine[3:,3:]
if (not np.allclose(np.diag(np.diag(A)), A)
or not np.all(np.diag(A) > 0)):
#.........这里部分代码省略.........