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


Python filters.laplace方法代码示例

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


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

示例1: drlse_edge

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import laplace [as 别名]
def drlse_edge(phi_0, g, lmda, mu, alfa, epsilon, timestep, iters, potentialFunction):  # Updated Level Set Function
    """

    :param phi_0: level set function to be updated by level set evolution
    :param g: edge indicator function
    :param lmda: weight of the weighted length term
    :param mu: weight of distance regularization term
    :param alfa: weight of the weighted area term
    :param epsilon: width of Dirac Delta function
    :param timestep: time step
    :param iters: number of iterations
    :param potentialFunction: choice of potential function in distance regularization term.
%              As mentioned in the above paper, two choices are provided: potentialFunction='single-well' or
%              potentialFunction='double-well', which correspond to the potential functions p1 (single-well)
%              and p2 (double-well), respectively.
    """
    phi = phi_0.copy()
    [vy, vx] = np.gradient(g)
    for k in range(iters):
        phi = NeumannBoundCond(phi)
        [phi_y, phi_x] = np.gradient(phi)
        s = np.sqrt(np.square(phi_x) + np.square(phi_y))
        smallNumber = 1e-10
        Nx = phi_x / (s + smallNumber)  # add a small positive number to avoid division by zero
        Ny = phi_y / (s + smallNumber)
        curvature = div(Nx, Ny)
        if potentialFunction == 'single-well':
            distRegTerm = filters.laplace(phi, mode='wrap') - curvature  # compute distance regularization term in equation (13) with the single-well potential p1.
        elif potentialFunction == 'double-well':
            distRegTerm = distReg_p2(phi)  # compute the distance regularization term in eqaution (13) with the double-well potential p2.
        else:
            print('Error: Wrong choice of potential function. Please input the string "single-well" or "double-well" in the drlse_edge function.')
        diracPhi = Dirac(phi, epsilon)
        areaTerm = diracPhi * g  # balloon/pressure force
        edgeTerm = diracPhi * (vx * Nx + vy * Ny) + diracPhi * g * curvature
        phi = phi + timestep * (mu * distRegTerm + lmda * edgeTerm + alfa * areaTerm)
    return phi 
开发者ID:Ramesh-X,项目名称:Level-Set,代码行数:39,代码来源:drlse_algo.py

示例2: distReg_p2

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import laplace [as 别名]
def distReg_p2(phi):
    """
        compute the distance regularization term with the double-well potential p2 in equation (16)
    """
    [phi_y, phi_x] = np.gradient(phi)
    s = np.sqrt(np.square(phi_x) + np.square(phi_y))
    a = (s >= 0) & (s <= 1)
    b = (s > 1)
    ps = a * np.sin(2 * np.pi * s) / (2 * np.pi) + b * (s - 1)  # compute first order derivative of the double-well potential p2 in equation (16)
    dps = ((ps != 0) * ps + (ps == 0)) / ((s != 0) * s + (s == 0))  # compute d_p(s)=p'(s)/s in equation (10). As s-->0, we have d_p(s)-->1 according to equation (18)
    return div(dps * phi_x - phi_x, dps * phi_y - phi_y) + filters.laplace(phi, mode='wrap') 
开发者ID:Ramesh-X,项目名称:Level-Set,代码行数:13,代码来源:drlse_algo.py

示例3: measure_sharpness

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import laplace [as 别名]
def measure_sharpness(img):
    """Measures the sharpeness of an image using the variance of the laplacian

    img: PIL.Image

    Returns the variance of the laplacian. Higher values mean a sharper image
    """
    img_gray = np.array(img.convert('L'), dtype=np.float32)
    return np.var(laplace(img_gray)) 
开发者ID:lmb-freiburg,项目名称:demon,代码行数:11,代码来源:helpers.py

示例4: test_laplace_comprehensions

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import laplace [as 别名]
def test_laplace_comprehensions():
    np.random.seed(0)

    a = np.random.random((3, 12, 14))
    d = da.from_array(a, chunks=(3, 6, 7))

    l2s = [da_ndf.laplace(d[i]) for i in range(len(d))]
    l2c = [da_ndf.laplace(d[i])[None] for i in range(len(d))]

    dau.assert_eq(np.stack(l2s), da.stack(l2s))
    dau.assert_eq(np.concatenate(l2c), da.concatenate(l2c)) 
开发者ID:dask,项目名称:dask-image,代码行数:13,代码来源:test__diff.py

示例5: test_laplace_compare

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import laplace [as 别名]
def test_laplace_compare():
    s = (10, 11, 12)
    a = np.arange(float(np.prod(s))).reshape(s)
    d = da.from_array(a, chunks=(5, 5, 6))

    dau.assert_eq(
        sp_ndf.laplace(a),
        da_ndf.laplace(d)
    ) 
开发者ID:dask,项目名称:dask-image,代码行数:11,代码来源:test__diff.py

示例6: gvf

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import laplace [as 别名]
def gvf(f, mu=0.05, iterations=30, anisotropic=False,
        ignore_second_term=False):
    # Gradient vector flow
    # Translated from https://github.com/smistad/3D-Gradient-Vector-Flow-for-Matlab
    f = (f - f.min()) / (f.max() - f.min())
    f = enforce_mirror_boundary(
        f)  # Enforce the mirror conditions on the boundary

    dx, dy, dz = np.gradient(f)  # Initialse with normal gradients
    '''
    Initialise the GVF vectors following S3 in
    Yu, Zeyun, and Chandrajit Bajaj. 
    "A segmentation-free approach for skeletonization of gray-scale images via anisotropic vector diffusion." 
    CVPR, 2004. CVPR 2004. 
    It only uses one of the surronding neighbours with the lowest intensity
    '''
    magsq = dx**2 + dy**2 + dz**2

    # Set up the initial vector field
    u = dx.copy()
    v = dy.copy()
    w = dz.copy()

    for i in tqdm(range(iterations)):
        # The boundary might not matter here
        # u = enforce_mirror_boundary(u)
        # v = enforce_mirror_boundary(v)
        # w = enforce_mirror_boundary(w)

        # Update the vector field
        if anisotropic:
            G = g_all(u, v, w)
            u += mu / 6. * div(np.sum(G * d(u), axis=0))
            v += mu / 6. * div(np.sum(G * d(v), axis=0))
            w += mu / 6. * div(np.sum(G * d(w), axis=0))
        else:
            u += mu * 6 * laplace(u)
            v += mu * 6 * laplace(v)
            w += mu * 6 * laplace(w)

        if not ignore_second_term:
            u -= (u - dx) * magsq
            v -= (v - dy) * magsq
            w -= (w - dz) * magsq

    return np.stack((u, v, w), axis=0) 
开发者ID:RivuletStudio,项目名称:rivuletpy,代码行数:48,代码来源:morphology.py


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