def compute_separators_morph(binary, scale, sepwiden=10, maxcolseps=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*maxcolseps) vert = morph.select_regions(vert, sl.dim0, min=20*scale, nbest=maxcolseps) return vert
def compute_separators_morph(binary: np.array, scale: float, sepwiden: int = 10, maxcolseps: int = 2) -> np.array: """Finds vertical black lines corresponding to column separators.""" logger.debug(u'Finding vertical black column lines') 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*maxcolseps) vert = morph.select_regions(vert, sl.dim0, min=20*scale, nbest=maxcolseps) return vert
def compute_colseps_conv(binary, scale=1.0, minheight=10, maxcolseps=2): """Find column separators by convolution and thresholding. Args: binary (numpy.array): scale (float): minheight (int): maxcolseps (int): Returns: Separators """ h, w = binary.shape # find vertical whitespace by thresholding 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) # find column edges by filtering grad = gaussian_filter(1.0*binary, (scale, scale*0.5), order=(0, 1)) grad = uniform_filter(grad, (10.0*scale, 1)) grad = (grad > 0.5*np.amax(grad)) # combine edges and whitespace seps = np.minimum(thresh, maximum_filter(grad, (int(scale), int(5*scale)))) seps = maximum_filter(seps, (int(2*scale), 1)) # select only the biggest column separators seps = morph.select_regions(seps, sl.dim0, min=minheight*scale, nbest=maxcolseps+1) return seps
def compute_separators_morph(binary: np.array, scale: float, sepwiden: int = 10, maxcolseps: int = 2) -> np.array: """Finds vertical black lines corresponding to column separators.""" logger.debug('Finding vertical black column lines') 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 * maxcolseps) vert = morph.select_regions(vert, sl.dim0, min=20 * scale, nbest=maxcolseps) return vert