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


Python segmentation.find_boundaries方法代码示例

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


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

示例1: save_prediction_image

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def save_prediction_image(_, panoptic_pred, img_info, out_dir, colors, num_stuff):
    msk, cat, obj, iscrowd = panoptic_pred

    img = Image.open(img_info["abs_path"])

    # Prepare folders and paths
    folder, img_name = path.split(img_info["rel_path"])
    img_name, _ = path.splitext(img_name)
    out_dir = path.join(out_dir, folder)
    ensure_dir(out_dir)
    out_path = path.join(out_dir, img_name + ".jpg")

    # Render semantic
    sem = cat[msk].numpy()
    crowd = iscrowd[msk].numpy()
    sem[crowd == 1] = 255

    sem_img = Image.fromarray(colors[sem])
    sem_img = sem_img.resize(img_info["original_size"][::-1])

    # Render contours
    is_background = (sem < num_stuff) | (sem == 255)
    msk = msk.numpy()
    msk[is_background] = 0

    contours = find_boundaries(msk, mode="outer", background=0).astype(np.uint8) * 255
    contours = dilation(contours)

    contours = np.expand_dims(contours, -1).repeat(4, -1)
    contours_img = Image.fromarray(contours, mode="RGBA")
    contours_img = contours_img.resize(img_info["original_size"][::-1])

    # Compose final image and save
    out = Image.blend(img, sem_img, 0.5).convert(mode="RGBA")
    out = Image.alpha_composite(out, contours_img)
    out.convert(mode="RGB").save(out_path) 
开发者ID:mapillary,项目名称:seamseg,代码行数:38,代码来源:test_panoptic.py

示例2: watersplit

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def watersplit(_probs, _points):
    points = _points.copy()

    points[points != 0] = np.arange(1, points.sum()+1)
    points = points.astype(float)

    probs = ndimage.black_tophat(_probs.copy(), 7)
    seg = watershed(probs, points)

    return find_boundaries(seg) 
开发者ID:ElementAI,项目名称:LCFCN,代码行数:12,代码来源:lcfcn_loss.py

示例3: compute_boundary_distances

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_boundary_distances(segm_ref, segm):
    """ compute distances among boundaries of two segmentation

    :param ndarray segm_ref: reference segmentation
    :param ndarray segm: input segmentation
    :return ndarray:

    >>> segm_ref = np.zeros((6, 10), dtype=int)
    >>> segm_ref[3:4, 4:5] = 1
    >>> segm = np.zeros((6, 10), dtype=int)
    >>> segm[:, 2:9] = 1
    >>> pts, dist = compute_boundary_distances(segm_ref, segm)
    >>> pts
    array([[2, 4],
           [3, 3],
           [3, 4],
           [3, 5],
           [4, 4]])
    >>> dist.tolist()
    [2.0, 1.0, 2.0, 3.0, 2.0]
    """
    assert segm_ref.shape == segm.shape, 'Ref. segm %r and segm %r should match' \
                                         % (segm_ref.shape, segm.shape)
    grid_y, grid_x = np.meshgrid(range(segm_ref.shape[1]),
                                 range(segm_ref.shape[0]))
    segr_boundary = sk_segm.find_boundaries(segm_ref, mode='thick')
    points = np.array([grid_x[segr_boundary].ravel(),
                       grid_y[segr_boundary].ravel()]).T
    segm_boundary = sk_segm.find_boundaries(segm, mode='thick')
    segm_distance = ndimage.distance_transform_edt(~segm_boundary)
    dist = segm_distance[segr_boundary].ravel()

    assert len(points) == len(dist), \
        'number of points and distances should be equal'
    return points, dist 
开发者ID:Borda,项目名称:pyImSegm,代码行数:37,代码来源:labeling.py

示例4: figure_segm_boundary_dist

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def figure_segm_boundary_dist(segm_ref, segm, subfig_size=9):
    """ visualise the boundary distances between two segmentation

    :param ndarray segm_ref: reference segmentation
    :param ndarray segm: estimated segmentation
    :param int subfig_size: maximal sub-figure size
    :return Figure:

    >>> seg = np.zeros((100, 100))
    >>> seg[35:80, 10:65] = 1
    >>> fig = figure_segm_boundary_dist(seg, seg.T)
    >>> isinstance(fig, matplotlib.figure.Figure)
    True
    """
    assert segm_ref.shape == segm.shape, \
        'ref segm %r and segm %r should match' % (segm_ref.shape, segm.shape)
    segr_boundary = segmentation.find_boundaries(segm_ref, mode='thick')
    segm_boundary = segmentation.find_boundaries(segm, mode='thick')
    segm_distance = ndimage.distance_transform_edt(~segm_boundary)

    norm_size = np.array(segm_ref.shape[:2]) / float(np.max(segm_ref.shape))
    fig_size = norm_size[::-1] * subfig_size * np.array([2, 1])
    fig, axarr = plt.subplots(ncols=2, figsize=fig_size)

    axarr[0].set_title('boundary distances with reference contour')
    im = axarr[0].imshow(segm_distance, cmap=plt.cm.Greys)
    plt.colorbar(im, ax=axarr[0])
    axarr[0].contour(segm_ref, cmap=plt.cm.jet)

    segm_distance[~segr_boundary] = 0
    axarr[1].set_title('distance projected to ref. boundary')
    im = axarr[1].imshow(segm_distance, cmap=plt.cm.Reds)
    plt.colorbar(im, ax=axarr[1])

    return fig 
开发者ID:Borda,项目名称:pyImSegm,代码行数:37,代码来源:drawing.py

示例5: compute_sdf

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf(img_gt, out_shape):
    """
    compute the signed distance map of binary mask
    input: segmentation, shape = (batch_size,c, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdf(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation
    normalize sdf to [-1,1]

    """

    img_gt = img_gt.astype(np.uint8)
    normalized_sdf = np.zeros(out_shape)

    for b in range(out_shape[0]): # batch size
        for c in range(out_shape[1]):
            posmask = img_gt[b].astype(np.bool)
            if posmask.any():
                negmask = ~posmask
                posdis = distance(posmask)
                negdis = distance(negmask)
                boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
                sdf = (negdis-np.min(negdis))/(np.max(negdis)-np.min(negdis)) - (posdis-np.min(posdis))/(np.max(posdis)-np.min(posdis))
                sdf[boundary==1] = 0
                normalized_sdf[b][c] = sdf
                assert np.min(sdf) == -1.0, print(np.min(posdis), np.max(posdis), np.min(negdis), np.max(negdis))
                assert np.max(sdf) ==  1.0, print(np.min(posdis), np.min(negdis), np.max(posdis), np.max(negdis))

    return normalized_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:32,代码来源:train_LA_MultiHead_SDF_L1PlusL2.py

示例6: compute_sdf1_1

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf1_1(img_gt, out_shape):
    """
    compute the signed distance map of binary mask
    input: segmentation, shape = (batch_size, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdm(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation

    """
    # print(type(segmentation), segmentation.shape)

    img_gt = img_gt.astype(np.uint8)
    if img_gt.shape != out_shape:
        img_gt = np.expand_dims(img_gt, 1)
    print('img_gt.shape: ', img_gt.shape)
    normalized_sdf = np.zeros(out_shape)

    for b in range(out_shape[0]): # batch size
            # ignore background
        for c in range(out_shape[1]):
            posmask = img_gt[b][c]
            negmask = 1-posmask
            posdis = distance(posmask)
            negdis = distance(negmask)
            boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
            sdf = (negdis-np.min(negdis))/(np.max(negdis)-np.min(negdis)) - (posdis-np.min(posdis))/(np.max(posdis)-np.min(posdis))
            sdf[boundary==1] = 0
            normalized_sdf[b][c] = sdf
            assert np.min(sdf) == -1.0, print(np.min(posdis), np.min(negdis), np.max(posdis), np.max(negdis))
            assert np.max(sdf) ==  1.0, print(np.min(posdis), np.min(negdis), np.max(posdis), np.max(negdis))

    return normalized_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:35,代码来源:train_LA_SDF.py

示例7: compute_sdf1_1

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf1_1(img_gt, out_shape):
    """
    compute the normalized signed distance map of binary mask
    input: segmentation, shape = (batch_size, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdf(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation
    normalize sdf to [-1, 1]
    """

    img_gt = img_gt.astype(np.uint8)

    normalized_sdf = np.zeros(out_shape)

    for b in range(out_shape[0]): # batch size
            # ignore background
        for c in range(1, out_shape[1]):
            posmask = img_gt[b].astype(np.bool)
            if posmask.any():
                negmask = ~posmask
                posdis = distance(posmask)
                negdis = distance(negmask)
                boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
                sdf = (negdis-np.min(negdis))/(np.max(negdis)-np.min(negdis)) - (posdis-np.min(posdis))/(np.max(posdis)-np.min(posdis))
                sdf[boundary==1] = 0
                normalized_sdf[b][c] = sdf

    return normalized_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:31,代码来源:train_LITS_BD.py

示例8: compute_sdf

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf(img_gt, out_shape):
    """
    compute the signed distance map of binary mask
    input: segmentation, shape = (batch_size, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdf(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation
    """

    img_gt = img_gt.astype(np.uint8)

    gt_sdf = np.zeros(out_shape)

    for b in range(out_shape[0]): # batch size
        for c in range(1, out_shape[1]):
            posmask = img_gt[b].astype(np.bool)
            if posmask.any():
                negmask = ~posmask
                posdis = distance(posmask)
                negdis = distance(negmask)
                boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
                sdf = negdis - posdis
                sdf[boundary==1] = 0
                gt_sdf[b][c] = sdf

    return gt_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:29,代码来源:train_LITS_BD.py

示例9: compute_sdf

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf(img_gt, out_shape):
    """
    compute the signed distance map of binary mask
    input: segmentation, shape = (batch_size, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdf(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation
    normalize sdf to [-1,1]

    """

    img_gt = img_gt.astype(np.uint8)
    normalized_sdf = np.zeros(out_shape)

    for b in range(out_shape[0]): # batch size
        for c in range(out_shape[1]):
            posmask = img_gt[b].astype(np.bool)
            if posmask.any():
                negmask = ~posmask
                posdis = distance(posmask)
                negdis = distance(negmask)
                boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
                sdf = (negdis-np.min(negdis))/(np.max(negdis)-np.min(negdis)) - (posdis-np.min(posdis))/(np.max(posdis)-np.min(posdis))
                sdf[boundary==1] = 0
                normalized_sdf[b][c] = sdf
                assert np.min(sdf) == -1.0, print(np.min(posdis), np.max(posdis), np.min(negdis), np.max(negdis))
                assert np.max(sdf) ==  1.0, print(np.min(posdis), np.min(negdis), np.max(posdis), np.max(negdis))

    return normalized_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:32,代码来源:train_LA_AAAISDF.py

示例10: compute_sdf01

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf01(segmentation):
    """
    compute the signed distance map of binary mask
    input: segmentation, shape = (batch_size, class, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdm(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation

    """
    # print(type(segmentation), segmentation.shape)

    segmentation = segmentation.astype(np.uint8)
    if len(segmentation.shape) == 4: # 3D image
        segmentation = np.expand_dims(segmentation, 1)
    normalized_sdf = np.zeros(segmentation.shape)
    if segmentation.shape[1] == 1:
        dis_id = 0
    else:
        dis_id = 1
    for b in range(segmentation.shape[0]): # batch size
        for c in range(dis_id, segmentation.shape[1]): # class_num
            # ignore background
            posmask = segmentation[b][c]
            negmask = ~posmask
            posdis = distance(posmask)
            negdis = distance(negmask)
            boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
            sdf = negdis/np.max(negdis)/2 - posdis/np.max(posdis)/2 + 0.5
            sdf[boundary>0] = 0.5
            normalized_sdf[b][c] = sdf
    return normalized_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:34,代码来源:losses.py

示例11: compute_sdf1_1

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf1_1(segmentation):
    """
    compute the signed distance map of binary mask
    input: segmentation, shape = (batch_size, class, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdm(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation

    """
    # print(type(segmentation), segmentation.shape)

    segmentation = segmentation.astype(np.uint8)
    if len(segmentation.shape) == 4: # 3D image
        segmentation = np.expand_dims(segmentation, 1)
    normalized_sdf = np.zeros(segmentation.shape)
    if segmentation.shape[1] == 1:
        dis_id = 0
    else:
        dis_id = 1
    for b in range(segmentation.shape[0]): # batch size
        for c in range(dis_id, segmentation.shape[1]): # class_num
            # ignore background
            posmask = segmentation[b][c]
            negmask = ~posmask
            posdis = distance(posmask)
            negdis = distance(negmask)
            boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
            sdf = negdis/np.max(negdis) - posdis/np.max(posdis)
            sdf[boundary>0] = 0
            normalized_sdf[b][c] = sdf
    return normalized_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:34,代码来源:losses.py

示例12: compute_sdf

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf(img_gt, out_shape):
    """
    compute the signed distance map of binary mask
    input: segmentation, shape = (batch_size,c, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdf(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation
    normalize sdf to [-1,1]

    """

    img_gt = img_gt.astype(np.uint8)
    normalized_sdf = np.zeros(out_shape)

    for b in range(out_shape[0]): # batch size
        for c in range(out_shape[1]):
            posmask = img_gt[b].astype(np.bool)
            if posmask.any():
                negmask = ~posmask
                posdis = distance(posmask)
                negdis = distance(negmask)
                boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
                sdf = (negdis-np.min(negdis))/(np.max(negdis)-np.min(negdis))*negmask - (posdis-np.min(posdis))/(np.max(posdis)-np.min(posdis))*posmask
                sdf[boundary==1] = 0
                normalized_sdf[b][c] = sdf

    return normalized_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:30,代码来源:train_LiTS_MultiHead_SDF_L1.py

示例13: compute_sdf

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf(img_gt, out_shape):
    """
    compute the signed distance map of binary mask
    input: segmentation, shape = (batch_size,c, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdf(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation
    normalize sdf to [-1,1]

    """

    img_gt = img_gt.astype(np.uint8)
    normalized_sdf = np.zeros(out_shape)

    for b in range(out_shape[0]): # batch size
        for c in range(out_shape[1]):
            posmask = img_gt[b].astype(np.bool)
            if posmask.any():
                negmask = ~posmask
                posdis = distance(posmask)
                negdis = distance(negmask)
                boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
                sdf = (negdis-np.min(negdis))/(np.max(negdis)-np.min(negdis)) - (posdis-np.min(posdis))/(np.max(posdis)-np.min(posdis))
                sdf[boundary==1] = 0
                normalized_sdf[b][c] = sdf

    return normalized_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:30,代码来源:train_LITS_Rec_SDF_L2.py

示例14: compute_sdf1_1

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf1_1(img_gt, out_shape):
    """
    compute the normalized signed distance map of binary mask
    input: segmentation, shape = (batch_size, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdf(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation
    normalize sdf to [-1, 1]
    """

    img_gt = img_gt.astype(np.uint8)

    normalized_sdf = np.zeros(out_shape)

    for b in range(out_shape[0]): # batch size
            # ignore background
        for c in range(1, out_shape[1]):
            posmask = img_gt[b]
            negmask = 1-posmask
            posdis = distance(posmask)
            negdis = distance(negmask)
            boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
            sdf = (negdis-np.min(negdis))/(np.max(negdis)-np.min(negdis)) - (posdis-np.min(posdis))/(np.max(posdis)-np.min(posdis))
            sdf[boundary==1] = 0
            normalized_sdf[b][c] = sdf
            assert np.min(sdf) == -1.0, print(np.min(posdis), np.min(negdis), np.max(posdis), np.max(negdis))
            assert np.max(sdf) ==  1.0, print(np.min(posdis), np.min(negdis), np.max(posdis), np.max(negdis))

    return normalized_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:32,代码来源:train_LA_BD.py

示例15: compute_sdf

# 需要导入模块: from skimage import segmentation [as 别名]
# 或者: from skimage.segmentation import find_boundaries [as 别名]
def compute_sdf(img_gt, out_shape):
    """
    compute the signed distance map of binary mask
    input: segmentation, shape = (batch_size, x, y, z)
    output: the Signed Distance Map (SDM) 
    sdf(x) = 0; x in segmentation boundary
             -inf|x-y|; x in segmentation
             +inf|x-y|; x out of segmentation
    """

    img_gt = img_gt.astype(np.uint8)

    gt_sdf = np.zeros(out_shape)

    for b in range(out_shape[0]): # batch size
        for c in range(1, out_shape[1]):
            posmask = img_gt[b]
            negmask = 1-posmask
            posdis = distance(posmask)
            negdis = distance(negmask)
            boundary = skimage_seg.find_boundaries(posmask, mode='inner').astype(np.uint8)
            sdf = negdis - posdis
            sdf[boundary==1] = 0
            gt_sdf[b][c] = sdf

    return gt_sdf 
开发者ID:JunMa11,项目名称:SegWithDistMap,代码行数:28,代码来源:train_LA_BD.py


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