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


Python morphology.square方法代碼示例

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


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

示例1: getTerminationBifurcation

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [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

示例2: updateRasterInfo

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [as 別名]
def updateRasterInfo(self, **kwargs):
        kwargs['output_info']['statistics'] = ()
        kwargs['output_info']['histogram'] = ()

        self.window = square(int(kwargs.get('size', 3)))
        m = kwargs.get('measure', 'Mean').lower()
        if m == 'minimum':
            self.func = rank.minimum
        elif m == 'maximum':
            self.func = rank.maximum
        elif m == 'mean':
            self.func = rank.mean
        elif m == 'bilateral mean':
            self.func = rank.mean_bilateral
        elif m == 'median':
            self.func = rank.median
        elif m == 'sum':
            self.func = rank.sum
        elif m == 'entropy':
            self.func = rank.entropy
        elif m == 'threshold':
            self.func = rank.threshold
        elif m == 'autolevel':
            self.func = rank.autolevel
        return kwargs 
開發者ID:Esri,項目名稱:raster-functions,代碼行數:27,代碼來源:RankFilter.py

示例3: generate_wsl

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [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: generate_wsl

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [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

示例5: dilate

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [as 別名]
def dilate(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 = dilate(data.data, size, shape, dim)
        return im_out
    else:
        return dilation(data, selem=_get_selem(shape, size, dim), out=None) 
開發者ID:neuropoly,項目名稱:spinalcordtoolbox,代碼行數:19,代碼來源:math.py

示例6: erode

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [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: thicken_drawings

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [as 別名]
def thicken_drawings(image):
    """
    :param image: [H, W, 3], np.float32
    :return:
    """
    img = np.array(image[:, :, 0], dtype=np.uint8)

    img = 255 - img
    dilated_img = sm.dilation(img, sm.square(2))
    dilated_img = 255 - dilated_img  # [H, W]

    rst_img3 = np.zeros([dilated_img.shape[0], dilated_img.shape[1], 3], dtype=np.uint8)
    for i in range(3):
        rst_img3[:, :, i] = dilated_img

    return rst_img3 
開發者ID:SketchyScene,項目名稱:SketchySceneColorization,代碼行數:18,代碼來源:input_pipeline.py

示例8: subtract_background_median

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [as 別名]
def subtract_background_median(z, footprint):
    """Remove background using a median filter.

    Parameters
    ----------
    footprint : int
        size of the window that is convoluted with the array to determine
        the median. Should be large enough that it is about 3x as big as the
        size of the peaks.

    Returns
    -------
        Pattern with background subtracted as np.array
    """

    selem = morphology.square(footprint)
    # skimage only accepts input image as uint16
    bg_subtracted = z - filters.median(z.astype(np.uint16), selem).astype(z.dtype)

    return np.maximum(bg_subtracted, 0) 
開發者ID:pyxem,項目名稱:pyxem,代碼行數:22,代碼來源:expt_utils.py

示例9: isolate_islands

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [as 別名]
def isolate_islands(prediction, threshold):
    bw = closing(prediction > threshold , square(3))
    labelled = label(bw)  
    regions_properties = regionprops(labelled)
    max_region_area = 0
    select_region = 0
    for region in regions_properties:
        if region.area > max_region_area:
            max_region_area = region.area
            select_region = region
    output = np.zeros(labelled.shape)
    if select_region == 0:
        return output
    else:
        output[labelled == select_region.label] = 1
        return output

# input: output from bwperim -- 2D image with perimeter of the ellipse = 1 
開發者ID:pydsgz,項目名稱:DeepVOG,代碼行數:20,代碼來源:draw_ellipse.py

示例10: key_point_to_mask

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [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 square [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: __call__

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [as 別名]
def __call__(self, img_small):
        m = morphology.square(self.square_size)
        img_th = morphology.black_tophat(img_small, m)
        img_sob = abs(filters.sobel_v(img_th))
        img_closed = morphology.closing(img_sob, m)
        threshold = filters.threshold_otsu(img_closed)
        return img_closed > threshold 
開發者ID:konstantint,項目名稱:PassportEye,代碼行數:9,代碼來源:image.py

示例13: produce_ma_mask

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [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

示例14: points_to_rectangle_mask

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [as 別名]
def points_to_rectangle_mask(shape, top_left, bottom_right, width=1):
    """Convert two points into a rectangle boolean mask.

    Parameters
    ----------
    shape : tuple
        Represents the `(height, width)` of the final mask.

    top_left : tuple
        Two element tuple representing `(row, column)` of the top left corner of the inner rectangle.

    bottom_right : tuple
        Two element tuple representing `(row, column)` of the bottom right corner of the inner rectangle.

    width : int
        Width of the edge of the rectangle. Note that it is generated by dilation.

    Returns
    -------
    rectangle_mask : np.ndarray
        Boolean mask of shape `shape` where True entries represent the edge of the rectangle.

    Notes
    -----
    The output can be easily used for quickly visualizing a rectangle in an image. One simply does
    something like img[rectangle_mask] = 255.

    """
    if len(shape) != 2:
        raise ValueError('Only works for 2 dimensional arrays')

    rectangle_mask = np.zeros(shape, dtype=np.bool)
    rr, cc = rectangle_perimeter(top_left, bottom_right)
    rectangle_mask[rr, cc] = True
    rectangle_mask = dilation(rectangle_mask, square(width))

    return rectangle_mask 
開發者ID:jankrepl,項目名稱:pychubby,代碼行數:39,代碼來源:utils.py

示例15: get_rough_detection

# 需要導入模塊: from skimage import morphology [as 別名]
# 或者: from skimage.morphology import square [as 別名]
def get_rough_detection(self, img, bigsize=40.0, smallsize=4.0, thresh = 0):
        diff = self.difference_of_gaussian(-img, bigsize, smallsize)
        diff[diff>thresh] = 1
        
        se = morphology.square(4)
        ero = morphology.erosion(diff, se)
        
        labimage = label(ero)
        #rec = morphology.reconstruction(ero, img, method='dilation').astype(np.dtype('uint8'))
        
        # connectivity=1 corresponds to 4-connectivity.
        morphology.remove_small_objects(labimage, min_size=600, connectivity=1, in_place=True)
        #res = np.zeros(img.shape)
        ero[labimage==0] = 0
        ero = 1 - ero
        labimage = label(ero)
        morphology.remove_small_objects(labimage, min_size=400, connectivity=1, in_place=True)
        ero[labimage==0] = 0
        res = 1 - ero
        res[res>0] = 255
        
        #temp = 255 - temp
        #temp = morphology.remove_small_objects(temp, min_size=400, connectivity=1, in_place=True)
        #res = 255 - temp
        
        return res 
開發者ID:PeterJackNaylor,項目名稱:DRFNS,代碼行數:28,代碼來源:segmentation_test.py


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