예제 #1
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
예제 #2
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
예제 #3
0
 def compute_colseps_mconv(self, binary, scale=1.0):
     """Find column separators using a combination of morphological
     operations and convolution."""
     #  h, w = binary.shape
     smoothed = gaussian_filter(1.0 * binary, (scale, scale * 0.5))
     smoothed = uniform_filter(smoothed, (5.0 * scale, 1))
     thresh = (smoothed < np.amax(smoothed) * 0.1)
     blocks = morph.rb_closing(binary, (int(4 * scale), int(4 * scale)))
     seps = np.minimum(blocks, thresh)
     seps = morph.select_regions(seps,
                                 sl.dim0,
                                 min=self.parameter['csminheight'] * scale,
                                 nbest=self.parameter['maxcolseps'])
     blocks = morph.r_dilation(blocks, (5, 5))
     seps = np.maximum(seps, 1 - blocks)
     return seps
예제 #4
0
def compute_colseps_mconv(binary, scale=1.0):
    """Find column separators using a combination of morphological
    operations and convolution."""
    h, w = binary.shape
    smoothed = gaussian_filter(1.0 * binary, (scale, scale * 0.5))
    smoothed = uniform_filter(smoothed, (5.0 * scale, 1))
    thresh = (smoothed < amax(smoothed) * 0.1)
    DSAVE("1thresh", thresh)
    blocks = morph.rb_closing(binary, (int(4 * scale), int(4 * scale)))
    DSAVE("2blocks", blocks)
    seps = minimum(blocks, thresh)
    seps = morph.select_regions(seps,
                                sl.dim0,
                                min=args['csminheight'] * scale,
                                nbest=args['maxcolseps'])
    DSAVE("3seps", seps)
    blocks = morph.r_dilation(blocks, (5, 5))
    DSAVE("4blocks", blocks)
    seps = maximum(seps, 1 - blocks)
    DSAVE("5combo", seps)
    return seps