本文整理汇总了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)
示例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)
示例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)