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


Python morphology.erosion方法代码示例

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


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

示例1: addNoiseAndGray

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def addNoiseAndGray(surf):
    # https://stackoverflow.com/questions/34673424/how-to-get-numpy-array-of-rgb-colors-from-pygame-surface
    imgdata = pygame.surfarray.array3d(surf)
    imgdata = imgdata.swapaxes(0, 1)
    # print('imgdata shape %s' % imgdata.shape)  # shall be IMG_HEIGHT * IMG_WIDTH
    imgdata2 = noise_generator('s&p', imgdata)

    img2 = Image.fromarray(np.uint8(imgdata2))
    # img2.save('/home/zhichyu/Downloads/2sp.jpg')
    grayscale2 = ImageOps.grayscale(img2)
    # grayscale2.save('/home/zhichyu/Downloads/2bw2.jpg')
    # return grayscale2

    array = np.asarray(np.uint8(grayscale2))
    # print('array.shape %s' % array.shape)
    selem = disk(random.randint(0, 1))
    eroded = erosion(array, selem)
    return eroded 
开发者ID:deepinsight,项目名称:insightocr,代码行数:20,代码来源:gen.py

示例2: getTerminationBifurcation

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def getTerminationBifurcation(img, mask):
    img = img == 255;
    (rows, cols) = img.shape;
    minutiaeTerm = np.zeros(img.shape);
    minutiaeBif = np.zeros(img.shape);
    
    for i in range(1,rows-1):
        for j in range(1,cols-1):
            if(img[i][j] == 1):
                block = img[i-1:i+2,j-1:j+2];
                block_val = np.sum(block);
                if(block_val == 2):
                    minutiaeTerm[i,j] = 1;
                elif(block_val == 4):
                    minutiaeBif[i,j] = 1;
    
    mask = convex_hull_image(mask>0)
    mask = erosion(mask, square(5))         # Structuing element for mask erosion = square(5)
    minutiaeTerm = np.uint8(mask)*minutiaeTerm
    return(minutiaeTerm, minutiaeBif) 
开发者ID:Utkarsh-Deshmukh,项目名称:Fingerprint-Feature-Extraction,代码行数:22,代码来源:getTerminationBifurcation.py

示例3: generate_wsl

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def generate_wsl(ws):
    """
    Generates watershed line. In particular, useful for seperating object
    in ground thruth as they are labeled by different intergers.
    """
    se = square(3)
    ero = ws.copy()
    ero[ero == 0] = ero.max() + 1
    ero = erosion(ero, se)
    ero[ws == 0] = 0

    grad = dilation(ws, se) - ero
    grad[ws == 0] = 0
    grad[grad > 0] = 255
    grad = grad.astype(np.uint8)
    return grad 
开发者ID:PeterJackNaylor,项目名称:DRFNS,代码行数:18,代码来源:utils.py

示例4: HreconstructionErosion

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def HreconstructionErosion(prob_img, h):
    """
    Performs a H minimma reconstruction via an erosion method.
    """

    def making_top_mask(x, lamb=h):
       return min(255, x + lamb)

    f = np.vectorize(making_top_mask)
    shift_prob_img = f(prob_img)

    seed = shift_prob_img
    mask = prob_img
    recons = reconstruction(
        seed, mask, method='erosion').astype(np.dtype('ubyte'))
    return recons 
开发者ID:PeterJackNaylor,项目名称:DRFNS,代码行数:18,代码来源:postprocessing.py

示例5: generate_wsl

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def generate_wsl(ws):
    """
    Generates watershed line that correspond to areas of
    touching objects.
    """
    se = square(3)
    ero = ws.copy()
    ero[ero == 0] = ero.max() + 1
    ero = erosion(ero, se)
    ero[ws == 0] = 0

    grad = dilation(ws, se) - ero
    grad[ws == 0] = 0
    grad[grad > 0] = 255
    grad = grad.astype(np.uint8)
    return grad 
开发者ID:PeterJackNaylor,项目名称:DRFNS,代码行数:18,代码来源:postprocessing.py

示例6: erode

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def erode(data, size, shape, dim=None):
    """
    Dilate data using ball structuring element
    :param data: Image or numpy array: 2d or 3d array
    :param size: int: If shape={'square', 'cube'}: Corresponds to the length of an edge (size=1 has no effect).
    If shape={'disk', 'ball'}: Corresponds to the radius, not including the center element (size=0 has no effect).
    :param shape: {'square', 'cube', 'disk', 'ball'}
    :param dim: {0, 1, 2}: Dimension of the array which 2D structural element will be orthogonal to. For example, if
    you wish to apply a 2D disk kernel in the X-Y plane, leaving Z unaffected, parameters will be: shape=disk, dim=2.
    :return: numpy array: data dilated
    """
    if isinstance(data, Image):
        im_out = data.copy()
        im_out.data = erode(data.data, size, shape, dim)
        return im_out
    else:
        return erosion(data, selem=_get_selem(shape, size, dim), out=None) 
开发者ID:neuropoly,项目名称:spinalcordtoolbox,代码行数:19,代码来源:math.py

示例7: markInvalid

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def markInvalid(seg, iter_num=2, do_2d=True):
    # find invalid 
    # if do erosion(seg==0), then miss the border
    if do_2d:
        stel=np.array([[1,1,1], [1,1,1]]).astype(bool)
        if len(seg.shape)==2:
            out = binary_dilation(seg>0, structure=stel, iterations=iter_num)
            seg[out==0] = -1
        else: # save memory
            for z in range(seg.shape[0]):
                tmp = seg[z] # by reference
                out = binary_dilation(tmp>0, structure=stel, iterations=iter_num)
                tmp[out==0] = -1
    else:
        stel=np.array([[1,1,1], [1,1,1], [1,1,1]]).astype(bool)
        out = binary_dilation(seg>0, structure=stel, iterations=iter_num)
        seg[out==0] = -1
    return seg 
开发者ID:zudi-lin,项目名称:pytorch_connectomics,代码行数:20,代码来源:data_segmentation.py

示例8: erode_image

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def erode_image(mask, erode_selem_size):
    """Erode mask.

    Args:
        mask (numpy.ndarray): Mask of shape (H x W) or multiple masks of shape (C x H x W).
        erode_selem_size (int): Size of rectangle structuring element used for erosion.

    Returns:
        numpy.ndarray: Eroded mask of shape (H x W) or multiple masks of shape (C x H x W).

    """
    if not erode_selem_size > 0:
        return mask
    selem = rectangle(erode_selem_size, erode_selem_size)
    if mask.ndim == 2:
        eroded_image = erosion(mask, selem=selem)
    else:
        eroded_image = []
        for category_mask in mask:
            eroded_image.append(erosion(category_mask, selem=selem))
            eroded_image = np.stack(eroded_image)
    return add_dropped_objects(mask, eroded_image) 
开发者ID:neptune-ai,项目名称:open-solution-mapping-challenge,代码行数:24,代码来源:postprocessing.py

示例9: make_boundaries

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def make_boundaries(label, thickness=None):
        """
        Input is an image label, output is a numpy array mask encoding the boundaries of the objects
        Extract pixels at the true boundary by dilation - erosion of label.
        Don't just pick the void label as it is not exclusive to the boundaries.
        """
        assert(thickness is not None)
        import skimage.morphology as skm
        void = 255
        mask = np.logical_and(label > 0, label != void)[0]
        selem = skm.disk(thickness)
        boundaries = np.logical_xor(skm.dilation(mask, selem),
                                    skm.erosion(mask, selem))
        return boundaries 
开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:16,代码来源:cityscapes.py

示例10: key_point_to_mask

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def key_point_to_mask(key_points, img_size, radius=6):
    new_points = expand_key_points(key_points, radius)
    mask = np.zeros(shape=img_size, dtype=bool)

    for i, joint in enumerate(list(key_points) + new_points):
        if KEY_POINT_MISSING_VALUE in joint:
            continue
        yy, xx = circle(joint[0], joint[1], radius=radius, shape=img_size)
        mask[yy, xx] = True
    mask = dilation(mask, square(radius + 3))
    mask = erosion(mask, square(radius + 3))
    return mask 
开发者ID:budui,项目名称:Human-Pose-Transfer,代码行数:14,代码来源:generate_pose_map_add_mask.py

示例11: produce_ma_mask

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def produce_ma_mask(kp_array, img_size, point_radius=4):
    from skimage.morphology import dilation, erosion, square
    mask = np.zeros(shape=img_size, dtype=bool)
    limbs = [[2, 3], [2, 6], [3, 4], [4, 5], [6, 7], [7, 8], [2, 9], [9, 10],
             [10, 11], [2, 12], [12, 13], [13, 14], [2, 1], [1, 15], [15, 17],
             [1, 16], [16, 18], [2, 17], [2, 18], [9, 12], [12, 6], [9, 3], [17, 18]]
    limbs = np.array(limbs) - 1
    for f, t in limbs:
        from_missing = kp_array[f][0] == MISSING_VALUE or kp_array[f][1] == MISSING_VALUE
        to_missing = kp_array[t][0] == MISSING_VALUE or kp_array[t][1] == MISSING_VALUE
        if from_missing or to_missing:
            continue

        norm_vec = kp_array[f] - kp_array[t]
        norm_vec = np.array([-norm_vec[1], norm_vec[0]])
        norm_vec = point_radius * norm_vec / np.linalg.norm(norm_vec)

        vetexes = np.array([
            kp_array[f] + norm_vec,
            kp_array[f] - norm_vec,
            kp_array[t] - norm_vec,
            kp_array[t] + norm_vec
        ])
        yy, xx = polygon(vetexes[:, 0], vetexes[:, 1], shape=img_size)
        mask[yy, xx] = True

    for i, joint in enumerate(kp_array):
        if kp_array[i][0] == MISSING_VALUE or kp_array[i][1] == MISSING_VALUE:
            continue
        yy, xx = circle(joint[0], joint[1], radius=point_radius, shape=img_size)
        mask[yy, xx] = True

    mask = dilation(mask, square(5))
    mask = erosion(mask, square(5))
    return mask 
开发者ID:budui,项目名称:Human-Pose-Transfer,代码行数:37,代码来源:pose_utils.py

示例12: produce_ma_mask

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def produce_ma_mask(kp_array, img_size, point_radius=4):
    from skimage.morphology import dilation, erosion, square
    mask = np.zeros(shape=img_size, dtype=bool)
    limbs = [[2,3], [2,6], [3,4], [4,5], [6,7], [7,8], [2,9], [9,10],
              [10,11], [2,12], [12,13], [13,14], [2,1], [1,15], [15,17],
               [1,16], [16,18], [2,17], [2,18], [9,12], [12,6], [9,3], [17,18]]
    limbs = np.array(limbs) - 1
    for f, t in limbs:
        from_missing = kp_array[f][0] == MISSING_VALUE or kp_array[f][1] == MISSING_VALUE
        to_missing = kp_array[t][0] == MISSING_VALUE or kp_array[t][1] == MISSING_VALUE
        if from_missing or to_missing:
            continue

        norm_vec = kp_array[f] - kp_array[t]
        norm_vec = np.array([-norm_vec[1], norm_vec[0]])
        norm_vec = point_radius * norm_vec / np.linalg.norm(norm_vec)


        vetexes = np.array([
            kp_array[f] + norm_vec,
            kp_array[f] - norm_vec,
            kp_array[t] - norm_vec,
            kp_array[t] + norm_vec
        ])
        yy, xx = polygon(vetexes[:, 0], vetexes[:, 1], shape=img_size)
        mask[yy, xx] = True

    for i, joint in enumerate(kp_array):
        if kp_array[i][0] == MISSING_VALUE or kp_array[i][1] == MISSING_VALUE:
            continue
        yy, xx = circle(joint[0], joint[1], radius=point_radius, shape=img_size)
        mask[yy, xx] = True

    mask = dilation(mask, square(5))
    mask = erosion(mask, square(5))
    return mask 
开发者ID:Lotayou,项目名称:everybody_dance_now_pytorch,代码行数:38,代码来源:pose_utils.py

示例13: overlay

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def overlay(self, img, imbin, contour=False):
        colim = color.gray2rgb(img)
        colorvalue = (0, 100, 200)
        if contour:
            se = morphology.diamond(2)
            ero = morphology.erosion(imbin, se)
            grad = imbin - ero
            colim[grad > 0] = colorvalue
        else:
            colim[imbin>0] = colorvalue
            
        return colim 
开发者ID:PeterJackNaylor,项目名称:DRFNS,代码行数:14,代码来源:segmentation_test.py

示例14: morpho_rec

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def morpho_rec(self, img, size=10):
        # internal gradient of the cells: 
        se = morphology.diamond(size)
        ero = morphology.erosion(img, se)
        rec = morphology.reconstruction(ero, img, method='dilation').astype(np.dtype('uint8'))
                
        return rec 
开发者ID:PeterJackNaylor,项目名称:DRFNS,代码行数:9,代码来源:segmentation_test.py

示例15: morpho_rec2

# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import erosion [as 别名]
def morpho_rec2(self, img, size=10):
        # internal gradient of the cells: 
        se = morphology.diamond(size)
        dil = morphology.dilation(img, se)
        rec = morphology.reconstruction(dil, img, method='erosion').astype(np.dtype('uint8'))
                
        return rec 
开发者ID:PeterJackNaylor,项目名称:DRFNS,代码行数:9,代码来源:segmentation_test.py


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