Beispiel #1
0
def compute_separators_morph_horizontal(binary, scale, widen=True):
    """Finds vertical black lines corresponding to column separators."""
    span = 4
    d0 = span  #int(max(5, scale / 5))
    if widen:
        d1 = span + 1
    else:
        d1 = span
    thick = morph.r_dilation(binary, (d1, d0))
    hor = morph.r_opening(thick, (1, int(4 * scale)))
    hor = morph.r_erosion(hor, (span, d0 // 2))

    return hor
Beispiel #2
0
def compute_separators_morph_vertical(binary, scale, widen=True):
    """Finds vertical black lines corresponding to column separators."""
    span = 3  #min(5,  int(scale * 0.2))

    d0 = span
    if widen:
        d1 = span + 1
    else:
        d1 = span
    thick = morph.r_dilation(binary, (d0, d1))
    vert = morph.r_opening(thick, (int(2 * scale), 1))
    vert = morph.r_erosion(vert, (d0 // 2, span))

    return vert
Beispiel #3
0
def compute_gradmaps(binary, scale):
    # use gradient filtering to find baselines
    binaryary = morph.r_opening(binary.astype(bool), (1, 1))  # CMND
    boxmap = compute_boxmap(binaryary, scale, binary)
    cleaned = boxmap * binaryary
    if args.usegauss:
        # this uses Gaussians
        grad = gaussian_filter(
            1.0 * cleaned,
            (args.vscale * 0.3 * scale, args.hscale * 6 * scale),
            order=(1, 0))
    else:
        # this uses non-Gaussian oriented filters
        grad = gaussian_filter(
            1.0 * cleaned,
            (max(4, args.vscale * 0.3 * scale), args.hscale * 1.0 * scale),
            order=(1, 0))
        grad = uniform_filter(grad,
                              (args.vscale, args.hscale * 1 * scale))  # CMND
    bottom = ocrolib.norm_max((grad < 0) * (-grad))
    #     bottom = minimum_filter(bottom,(2,6*scale))
    top = ocrolib.norm_max((grad > 0) * grad)
    #     top = minimum_filter(top,(2,6*scale))
    return bottom, top, boxmap