本文整理匯總了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)):
#.........這裏部分代碼省略.........