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


Python RectBivariateSpline.get_coeffs方法代码示例

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


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

示例1: main

# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import get_coeffs [as 别名]
def main():
    
    if len(sys.argv) != 2:
        print """
Usage: python img2spline.py [path_to_img] \n"""
        sys.exit(-1)
        
    else:
        path_to_img = sys.argv[1]
    
    
    img = Image.open(path_to_img).convert('L') # RGB -> [0..255]
    print "Image was opened and converted to grayscale."
    img.show()
    
    width, height = img.size
    
    data = np.array(list(img.getdata()), dtype=int)
    data = data.reshape((height, width))
    print "Data was extracted."
    
#    Start plotting original surface of image
    fig = plt.figure()
#    ax = fig.add_subplot(111, projection='3d')
    ax = fig.add_subplot(111)
    ax.invert_yaxis()
    x = range(0, width)
    y = range(0, height)
#    rev_y = range(height-1, -1, -1) # reverse y
    
    X, Y = np.meshgrid(x, y)
    print Y
    
    
    r_stride = 1 + width / 20 
    c_stride = 1 + height / 20
#    ax.plot_surface(X, Y, data, rstride=r_stride, cstride=c_stride)
    mappable = ax.pcolor(X, Y, data)
    plt.colorbar(mappable)
    ax.set_title("Original grayscale image")
    ax.set_xlabel('Width (px)')
    ax.set_ylabel('Height (px)')
    plt.draw()
#    Finish plotting original surface of image
    
    
#    2D Interpolation here
    spline = RectBivariateSpline(x, y, data)
    
    print spline.get_coeffs()
    
    
    
    
    plt.show()
开发者ID:haalogen,项目名称:img2spline,代码行数:57,代码来源:img2spline.py

示例2: _approx

# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import get_coeffs [as 别名]
def _approx(fmapnii, s=14.):
    """
    Slice-wise approximation of a smooth 2D bspline
    credits: http://scipython.com/book/chapter-8-scipy/examples/two-dimensional-interpolation-\
    with-scipyinterpolaterectbivariatespline/

    """
    from scipy.interpolate import RectBivariateSpline
    from builtins import str, bytes

    if isinstance(fmapnii, (str, bytes)):
        fmapnii = nb.load(fmapnii)

    if not isinstance(s, (tuple, list)):
        s = np.array([s] * 2)

    data = fmapnii.get_data()
    zooms = fmapnii.header.get_zooms()

    knot_decimate = np.floor(s / np.array(zooms)[:2]).astype(np.uint8)
    knot_space = np.array(zooms)[:2] * knot_decimate

    xmax = 0.5 * data.shape[0] * zooms[0]
    ymax = 0.5 * data.shape[1] * zooms[1]

    x = np.arange(-xmax, xmax, knot_space[0])
    y = np.arange(-ymax, ymax, knot_space[1])

    x2 = np.arange(-xmax, xmax, zooms[0])
    y2 = np.arange(-ymax, ymax, zooms[1])

    coeffs = []
    nslices = data.shape[-1]
    for k in range(nslices):
        data2d = data[..., k]
        data2dsubs = data2d[::knot_decimate[0], ::knot_decimate[1]]
        interp_spline = RectBivariateSpline(x, y, data2dsubs)

        data[..., k] = interp_spline(x2, y2)
        coeffs.append(interp_spline.get_coeffs().reshape(data2dsubs.shape))

    # Save smoothed data
    hdr = fmapnii.header.copy()
    caff = fmapnii.affine
    datanii = nb.Nifti1Image(data.astype(np.float32), caff, hdr)

    # Save bspline coeffs
    caff[0, 0] = knot_space[0]
    caff[1, 1] = knot_space[1]
    coeffnii = nb.Nifti1Image(np.stack(coeffs, axis=2), caff, hdr)

    return datanii, coeffnii
开发者ID:rwblair,项目名称:preprocessing-workflow,代码行数:54,代码来源:bspline.py

示例3: range

# 需要导入模块: from scipy.interpolate import RectBivariateSpline [as 别名]
# 或者: from scipy.interpolate.RectBivariateSpline import get_coeffs [as 别名]


#now try to solve by grad descent
kacq2d=zeros(kfull.shape,complex)
kacq2d[t2_array,t1_array]=kacq
imgus=ifft2(ifftshift(kacq2d))
imgwvlt=pywt.wavedec2(abs(imgus),wavelet='db4',mode='symmetric')
Ny,Nx=imgus.shape

#fit smoothed phase, evaluate phase basis functions
ph_splfit=RectBivariateSpline(arange(imgus.shape[0]),arange(imgus.shape[1]),1.0*i_unwrap_2d(angle(imgus)),s=1.7e5)
spl_tx=ph_splfit.tck[0]
spl_ty=ph_splfit.tck[1]
spl_kx,spl_ky=ph_splfit.degrees
spl_ncoeffs=ph_splfit.get_coeffs().shape[0]
Sb=zeros([spl_ncoeffs,Nx,Ny],float)
spl_BVS=BivariateSpline()
spl_BVS.degrees=(spl_kx,spl_ky)
for j in range(spl_ncoeffs):
    spl_coeffs=zeros(spl_ncoeffs,float)
    spl_coeffs[j]=1.0
    spl_BVS.tck=(spl_tx,spl_ty,spl_coeffs)
    spl_bfunc=spl_BVS.ev(arange(Nx*Ny)%Ny,arange(Nx*Ny)/Ny)
    spl_bfunc.shape=(Nx,Ny)
    Sb[j,:,:]=transpose(spl_bfunc[:,:]) #unfortunately, spline funcs use transposed orientation convention


phest=ph_splfit.get_coeffs()
p0=append(compose_vec_from_wvlt(imgwvlt,imgus.shape,wavelet='db4',mode='symmetric'),phest)
l_w=[0.2]
开发者ID:aasalerno,项目名称:pyDirectionCompSense,代码行数:32,代码来源:phsplinetest.py


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