當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。