api.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:histonets-cv 作者: sul-cidr 项目源码 文件源码
def remove_ridges(image, width=6, threshold=160, dilation=1,
                  return_mask=False):
    """Detect ridges of width pixels using the highest eigenvector of the
    Hessian matrix, then create a binarized mask with threshold and remove
    it from image (set to black). Default values are optimized for text
    detection and removal.

    A dilation radius in pixels can be passed in to thicken the mask prior
    to being applied."""
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    # The value of sigma is calculated according to Steger's work:
    # An Unbiased Detector of Curvilinear Structures,
    # IEEE Transactions on Pattern Analysis and Machine Intelligence,
    # Vol. 20, No. 2, Feb 1998
    # http://ieeexplore.ieee.org/document/659930/
    sigma = (width / 2) / np.sqrt(3)
    hxx, hxy, hyy = feature.hessian_matrix(gray_image, sigma=sigma, order='xy')
    large_eigenvalues, _ = feature.hessian_matrix_eigvals(hxx, hxy, hyy)
    mask = convert(large_eigenvalues)
    mask = binarize_image(mask, method='boolean', threshold=threshold)
    if dilation:
        dilation = (2 * dilation) + 1
        dilation_kernel = np.ones((dilation, dilation), np.uint8)
        mask = cv2.dilate(mask, dilation_kernel)
    return image, 255 - mask
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号