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


Python morphology.binary_closing方法代碼示例

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


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

示例1: morphologie

# 需要導入模塊: from scipy.ndimage import morphology [as 別名]
# 或者: from scipy.ndimage.morphology import binary_closing [as 別名]
def morphologie(img_name, target_dir, target_name):
    img = cv2.imread(img_name,cv2.IMREAD_GRAYSCALE)

    thresh_hor = 195
    thresh_ver = 60
    hor = cv2.threshold(img, thresh_hor, 255, cv2.THRESH_BINARY)[1]
    ver = 255-cv2.threshold(img, thresh_ver, 255, cv2.THRESH_BINARY)[1]

    mat = np.ones((5,5))
    hor = binary_opening(hor, structure=mat, iterations=2).astype(np.uint8) * 255
    #hor = binary_closing(hor, structure=mat, iterations=1).astype(np.uint8)*255

    #mat = np.ones((3,3))
    ver = binary_opening(ver, structure=mat, iterations=2).astype(np.uint8) * 255
    #ver = binary_closing(ver, structure=mat, iterations=1).astype(np.uint8)*255

    cv2.imwrite(os.path.join(target_dir, 'h' + target_name + '.png'), hor)
    cv2.imwrite(os.path.join(target_dir, 'v' + target_name + '.png'), ver) 
開發者ID:weningerleon,項目名稱:TextileDefectDetection,代碼行數:20,代碼來源:morphologie.py

示例2: ShowBinaryArray

# 需要導入模塊: from scipy.ndimage import morphology [as 別名]
# 或者: from scipy.ndimage.morphology import binary_closing [as 別名]
def ShowBinaryArray(b, title=None):
  im = Image.fromarray(255*np.uint8(b))
  im.show(im, title)

#showBinaryArray(B)
# this kills small features and introduces an 11px black border on every side
#B = binary_closing(B, structure=np.ones((11,11)))
#showBinaryArray(B)
#
#sys.exit(0) 
開發者ID:danvk,項目名稱:oldnyc,代碼行數:12,代碼來源:find_pictures.py

示例3: degrade_line

# 需要導入模塊: from scipy.ndimage import morphology [as 別名]
# 或者: from scipy.ndimage.morphology import binary_closing [as 別名]
def degrade_line(im, eta=0.0, alpha=1.5, beta=1.5, alpha_0=1.0, beta_0=1.0):
    """
    Degrades a line image by adding noise.

    For parameter meanings consult [1].

    Args:
        im (PIL.Image): Input image
        eta (float):
        alpha (float):
        beta (float):
        alpha_0 (float):
        beta_0 (float):

    Returns:
        PIL.Image in mode '1'
    """
    logger.debug('Inverting and normalizing input image')
    im = pil2array(im)
    im = np.amax(im)-im
    im = im*1.0/np.amax(im)

    logger.debug('Calculating foreground distance transform')
    fg_dist = distance_transform_cdt(1-im, metric='taxicab')
    logger.debug('Calculating flip to white probability')
    fg_prob = alpha_0 * np.exp(-alpha * (fg_dist**2)) + eta
    fg_prob[im == 1] = 0
    fg_flip = np.random.binomial(1, fg_prob)

    logger.debug('Calculating background distance transform')
    bg_dist = distance_transform_cdt(im, metric='taxicab')
    logger.debug('Calculating flip to black probability')
    bg_prob = beta_0 * np.exp(-beta * (bg_dist**2)) + eta
    bg_prob[im == 0] = 0
    bg_flip = np.random.binomial(1, bg_prob)

    # flip
    logger.debug('Flipping')
    im -= bg_flip
    im += fg_flip

    logger.debug('Binary closing')
    sel = np.array([[1, 1], [1, 1]])
    im = binary_closing(im, sel)
    logger.debug('Converting to image')
    return array2pil(255-im.astype('B')*255) 
開發者ID:mittagessen,項目名稱:kraken,代碼行數:48,代碼來源:linegen.py


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