当前位置: 首页>>代码示例>>Python>>正文


Python AffineTransform.from_start_step方法代码示例

本文整理汇总了Python中nipy.core.reference.coordinate_map.AffineTransform.from_start_step方法的典型用法代码示例。如果您正苦于以下问题:Python AffineTransform.from_start_step方法的具体用法?Python AffineTransform.from_start_step怎么用?Python AffineTransform.from_start_step使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nipy.core.reference.coordinate_map.AffineTransform的用法示例。


在下文中一共展示了AffineTransform.from_start_step方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_affine_start_step

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_start_step [as 别名]
def test_affine_start_step():
    incs, outcs, aff = affine_v2w()
    start = aff[:3, 3]
    step = aff.diagonal()[:3]
    cm = AffineTransform.from_start_step(incs.coord_names, outcs.coord_names, start, step)
    yield assert_equal, cm.affine, aff
    yield assert_raises, ValueError, AffineTransform.from_start_step, "ijk", "xy", start, step
开发者ID:jonathan-taylor,项目名称:nipy,代码行数:9,代码来源:test_coordinate_map.py

示例2: fromarray

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_start_step [as 别名]
def fromarray(data, innames, outnames, coordmap=None):
    """Create an image from a numpy array.

    Parameters
    ----------
    data : numpy array
        A numpy array of three dimensions.
    innames : sequence
       a list of input axis names
    innames : sequence
       a list of output axis names
    coordmap : A `CoordinateMap`
        If not specified, an identity coordinate map is created.

    Returns
    -------
    image : An `Image` object

    See Also
    --------
    load : function for loading images
    save : function for saving images

    """
    ndim = len(data.shape)
    if not coordmap:
        coordmap = AffineTransform.from_start_step(innames,
                                                   outnames,
                                                   (0.,)*ndim,
                                                   (1.,)*ndim)
                                          
    return Image(data, coordmap)
开发者ID:cournape,项目名称:nipy,代码行数:34,代码来源:image.py

示例3: test_kernel

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_start_step [as 别名]
def test_kernel():
    # Verify the the convolution with a delta function
    # gives the correct answer.
    tol = 0.9999
    sdtol = 1.0e-8
    for x in range(6):
        shape = randint(30,60,(3,))
        ii, jj, kk = randint(11,17, (3,))

        coordmap = AffineTransform.from_start_step('ijk', 'xyz', 
                                          randint(5,20,(3,))*0.25,
                                          randint(5,10,(3,))*0.5)

        signal = np.zeros(shape)
        signal[ii,jj,kk] = 1.
        signal = Image(signal, coordmap=coordmap)
    
        kernel = LinearFilter(coordmap, shape, 
                              fwhm=randint(50,100)/10.)
        ssignal = kernel.smooth(signal)
        ssignal = np.asarray(ssignal)
        ssignal[:] *= kernel.norms[kernel.normalization]

        I = np.indices(ssignal.shape)
        I.shape = (kernel.coordmap.ndim[0], np.product(shape))
        i, j, k = I[:,np.argmax(ssignal[:].flat)]

        yield assert_equal, (i,j,k), (ii,jj,kk)

        Z = kernel.coordmap(I) - kernel.coordmap([i,j,k])

        _k = kernel(Z)
        _k.shape = ssignal.shape

        yield assert_true, (np.corrcoef(_k[:].flat, ssignal[:].flat)[0,1] > tol)

        yield assert_true, ((_k[:] - ssignal[:]).std() < sdtol)
            
        def _indices(i,j,k,axis):
            I = np.zeros((3,20))
            I[0] += i
            I[1] += j
            I[2] += k
            I[axis] += np.arange(-10,10)
            return I

        vx = ssignal[i,j,(k-10):(k+10)]
        vvx = coordmap(_indices(i,j,k,2)) - coordmap([[i],[j],[k]])
        yield assert_true, (np.corrcoef(vx, kernel(vvx))[0,1] > tol)

        vy = ssignal[i,(j-10):(j+10),k]
        vvy = coordmap(_indices(i,j,k,1)) - coordmap([[i],[j],[k]])
        yield assert_true, (np.corrcoef(vy, kernel(vvy))[0,1] > tol)

        vz = ssignal[(i-10):(i+10),j,k]
        vvz = coordmap(_indices(i,j,k,0)) - coordmap([[i],[j],[k]])
        yield assert_true, (np.corrcoef(vz, kernel(vvz))[0,1] > tol)
开发者ID:cournape,项目名称:nipy,代码行数:59,代码来源:test_kernel_smooth.py

示例4: test_kernel

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_start_step [as 别名]
def test_kernel():
    # Verify that convolution with a delta function gives the correct
    # answer.
    tol = 0.9999
    sdtol = 1.0e-8
    for x in range(6):
        shape = randint(30,60,(3,))
        # pos of delta
        ii, jj, kk = randint(11,17, (3,))
        # random affine coordmap (diagonal and translations)
        coordmap = AffineTransform.from_start_step('ijk', 'xyz', 
                                          randint(5,20,(3,))*0.25,
                                          randint(5,10,(3,))*0.5)
        # delta function in 3D array
        signal = np.zeros(shape)
        signal[ii,jj,kk] = 1.
        signal = Image(signal, coordmap=coordmap)
        # A filter with coordmap, shape matched to image
        kernel = LinearFilter(coordmap, shape, 
                              fwhm=randint(50,100)/10.)
        # smoothed normalized 3D array
        ssignal = kernel.smooth(signal).get_data()
        ssignal[:] *= kernel.norms[kernel.normalization]
        # 3 points * signal.size array
        I = np.indices(ssignal.shape)
        I.shape = (kernel.coordmap.ndims[0], np.product(shape))
        # location of maximum in smoothed array
        i, j, k = I[:, np.argmax(ssignal[:].flat)]
        # same place as we put it before smoothing?
        assert_equal((i,j,k), (ii,jj,kk))
        # get physical points position relative to position of delta
        Z = kernel.coordmap(I.T) - kernel.coordmap([i,j,k])
        _k = kernel(Z)
        _k.shape = ssignal.shape
        assert_true((np.corrcoef(_k[:].flat, ssignal[:].flat)[0,1] > tol))
        assert_true(((_k[:] - ssignal[:]).std() < sdtol))

        def _indices(i,j,k,axis):
            I = np.zeros((3,20))
            I[0] += i
            I[1] += j
            I[2] += k
            I[axis] += np.arange(-10,10)
            return I.T

        vx = ssignal[i,j,(k-10):(k+10)]
        xformed_ijk = coordmap([i, j, k])
        vvx = coordmap(_indices(i,j,k,2)) - xformed_ijk
        assert_true((np.corrcoef(vx, kernel(vvx))[0,1] > tol))
        vy = ssignal[i,(j-10):(j+10),k]
        vvy = coordmap(_indices(i,j,k,1)) - xformed_ijk
        assert_true((np.corrcoef(vy, kernel(vvy))[0,1] > tol))
        vz = ssignal[(i-10):(i+10),j,k]
        vvz = coordmap(_indices(i,j,k,0)) - xformed_ijk
        assert_true((np.corrcoef(vz, kernel(vvz))[0,1] > tol))
开发者ID:FNNDSC,项目名称:nipy,代码行数:57,代码来源:test_kernel_smooth.py


注:本文中的nipy.core.reference.coordinate_map.AffineTransform.from_start_step方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。