Beispiel #1
0
def compute_separators_morph(binary,scale,sepwiden=10,maxseps=2):
    """Finds vertical black lines corresponding to column separators."""
    d0 = int(max(5,scale/4))
    d1 = int(max(5,scale))+sepwiden
    thick = morph.r_dilation(binary,(d0,d1))
    vert = morph.rb_opening(thick,(10*scale,1))
    vert = morph.r_erosion(vert,(d0//2,sepwiden))
    vert = morph.select_regions(vert,sl.dim1,min=3,nbest=2*maxseps)
    vert = morph.select_regions(vert,sl.dim0,min=20*scale,nbest=maxseps)
    return vert
Beispiel #2
0
def compute_separators_morph(binary, scale, sepwiden, maxseps):
    """Finds vertical black lines corresponding to column separators."""
    d0 = int(max(5, scale / 4))
    d1 = int(max(5, scale)) + sepwiden
    thick = morph.r_dilation(binary, (d0, d1))
    vert = morph.rb_opening(thick, (10 * scale, 1))
    vert = morph.r_erosion(vert, (d0 // 2, sepwiden))
    vert = morph.select_regions(vert, sl.dim1, min=3, nbest=2 * maxseps)
    vert = morph.select_regions(vert, sl.dim0, min=20 * scale, nbest=maxseps)
    return vert
Beispiel #3
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 #4
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 #5
0
def compute_colseps_morph(binary, scale, maxseps=3, minheight=20, maxwidth=5):
    """Finds extended vertical whitespace corresponding to column separators
    using morphological operations."""
    boxmap = psegutils.compute_boxmap(binary, scale, (0.4, 5), dtype='B')
    bounds = morph.rb_closing(B(boxmap), (int(5 * scale), int(5 * scale)))
    bounds = maximum(B(1 - bounds), B(boxmap))
    cols = 1 - morph.rb_closing(boxmap, (int(20 * scale), int(scale)))
    cols = morph.select_regions(cols, sl.aspect, min=args.csminaspect)
    cols = morph.select_regions(cols,
                                sl.dim0,
                                min=args.csminheight * scale,
                                nbest=args.maxcolseps)
    cols = morph.r_erosion(cols, (int(0.5 + scale), 0))
    cols = morph.r_dilation(cols, (int(0.5 + scale), 0),
                            origin=(int(scale / 2) - 1, 0))
    return cols
Beispiel #6
0
 def compute_colseps_morph(self, binary, scale):
     """Finds extended vertical whitespace corresponding to column separators
     using morphological operations."""
     boxmap = psegutils.compute_boxmap(binary, scale, dtype='B')
     bounds = morph.rb_closing(B(boxmap), (int(5 * scale), int(5 * scale)))
     bounds = np.maximum(B(1 - bounds), B(boxmap))
     cols = 1 - morph.rb_closing(boxmap, (int(20 * scale), int(scale)))
     cols = morph.select_regions(cols,
                                 sl.aspect,
                                 min=self.parameter['csminaspect'])
     cols = morph.select_regions(cols,
                                 sl.dim0,
                                 min=self.parameter['csminheight'] * scale,
                                 nbest=self.parameter['maxcolseps'])
     cols = morph.r_erosion(cols, (int(0.5 + scale), 0))
     cols = morph.r_dilation(cols, (int(0.5 + scale), 0),
                             origin=(int(scale / 2) - 1, 0))
     return cols