當前位置: 首頁>>代碼示例>>Python>>正文


Python morphology.medial_axis方法代碼示例

本文整理匯總了Python中skimage.morphology.medial_axis方法的典型用法代碼示例。如果您正苦於以下問題:Python morphology.medial_axis方法的具體用法?Python morphology.medial_axis怎麽用?Python morphology.medial_axis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在skimage.morphology的用法示例。


在下文中一共展示了morphology.medial_axis方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: to_sdf

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import medial_axis [as 別名]
def to_sdf(self):
        """ Converts the 2D image to a 2D signed distance field.

        Returns
        -------
        :obj:`numpy.ndarray`
            2D float array of the signed distance field
        """
        # compute medial axis transform
        skel, sdf_in = morph.medial_axis(self.data, return_distance=True)
        useless_skel, sdf_out = morph.medial_axis(
            np.iinfo(np.uint8).max - self.data, return_distance=True)

        # convert to true sdf
        sdf = sdf_out - sdf_in
        return sdf 
開發者ID:BerkeleyAutomation,項目名稱:perception,代碼行數:18,代碼來源:image.py

示例2: vectorize_lines

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import medial_axis [as 別名]
def vectorize_lines(im: np.ndarray, threshold: float = 0.2, min_sp_dist: int = 10):
    """
    Vectorizes lines from a binarized array.

    Args:
        im (np.ndarray): Array of shape (3, H, W) with the first dimension
                         being probabilities for (start_separators,
                         end_separators, baseline).

    Returns:
        [[x0, y0, ... xn, yn], [xm, ym, ..., xk, yk], ... ]
        A list of lists containing the points of all baseline polylines.
    """
    # split into baseline and separator map
    st_map = im[0]
    end_map = im[1]
    sep_map = st_map + end_map
    bl_map = im[2]
    # binarize
    bin = im > threshold
    skel, skel_dist_map = medial_axis(bin[2], return_distance=True)
    elongation_offset = np.max(skel_dist_map)
    sp_can = _find_superpixels(skel, heatmap=bl_map, min_sp_dist=min_sp_dist)
    if not sp_can.size:
        logger.warning('No superpixel candidates found in network output. Likely empty page.')
        return []
    intensities = _compute_sp_states(sp_can, bl_map, st_map, end_map)
    clusters = _cluster_lines(intensities)
    lines = _interpolate_lines(clusters, elongation_offset, bl_map.shape, st_map, end_map)
    return lines 
開發者ID:mittagessen,項目名稱:kraken,代碼行數:32,代碼來源:segmentation.py

示例3: place_routers_on_skeleton

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import medial_axis [as 別名]
def place_routers_on_skeleton(d, cmethod):
    wireless = np.where(d["graph"] == Cell.Wireless, 1, 0)
    # perform skeletonization
    skeleton = skeletonize(wireless)
    med_axis = medial_axis(wireless)

    skel = skeleton
    # skel = med_axis
    # get all skeleton positions
    pos = []
    for i in range(skel.shape[0]):
        for j in range(skel.shape[1]):
            if skel[i][j]:
                pos.append((i, j))

    budget = d['budget']
    shuffle(pos)

    max_num_routers = min([int(d['budget'] / d['price_router']), len(pos)])
    print("Num of routers constrained by:")
    print(" budget:   %d" % int(int(d['budget'] / d['price_router'])))
    print(" skeleton: %d" % len(pos))

    for i in tqdm(range(max_num_routers), desc="Placing Routers"):
        new_router = pos[i]
        a, b = new_router

        # check if remaining budget is enough
        d["graph"][a][b] = Cell.Router
        d, ret, cost = _add_cabel(d, new_router, budget)
        budget -= cost

        if not ret:
            break

    return d 
開發者ID:sbrodehl,項目名稱:HashCode,代碼行數:38,代碼來源:best_solution_in_the_wuuuuuuurld.py

示例4: place_routers_on_skeleton_iterative

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import medial_axis [as 別名]
def place_routers_on_skeleton_iterative(d, cmethod):
    budget = d['budget']
    R = d['radius']
    max_num_routers = int(d['budget'] / d['price_router'])
    coverage = np.where(d["graph"] == Cell.Wireless, 1, 0).astype(np.bool)

    pbar = tqdm(range(max_num_routers), desc="Placing Routers")
    while budget > 0:
        # perform skeletonization
        # skeleton = skeletonize(coverage)
        skeleton = medial_axis(coverage)
        # get all skeleton positions
        pos = np.argwhere(skeleton > 0).tolist()
        # escape if no positions left
        if not len(pos):
            break
        # get a random position
        shuffle(pos)
        a, b = pos[0]
        # place router
        d["graph"][a][b] = Cell.Router
        d, ret, cost = _add_cabel(d, (a, b), budget)
        if not ret:
            print("No budget available!")
            break
        budget -= cost
        # refresh wireless map by removing new coverage
        m = wireless_access(a, b, R, d['graph']).astype(np.bool)
        coverage[(a - R):(a + R + 1), (b - R):(b + R + 1)] &= ~m
        pbar.update()
    pbar.close()

    return d 
開發者ID:sbrodehl,項目名稱:HashCode,代碼行數:35,代碼來源:best_solution_in_the_wuuuuuuurld.py


注:本文中的skimage.morphology.medial_axis方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。