def find_columns(self): """Get columns in a section of the image """ portion = iulib.bytearray() iulib.extract_subimage(portion, self.inverted, 0, 0, self.inverted.dim(0), self.topptr) projection = high_pass_median(iulib.numpy(portion).sum(axis=1), 0.20) posscols = self.get_possible_columns(projection) bestcols = self.filter_columns(posscols, int(self._params.get("columns", 1))) self.columns.extend(bestcols)
def remove_border(narray, average_char_height): """Try and remove anything that's in a likely border region and return the subimage.""" na = iulib.numpy(narray) hpr = na.sum(axis=0) vpr = na.sum(axis=1) hhp = high_pass_median(hpr, 5.0 / average_char_height) vhp = high_pass_median(vpr, 5.0 / average_char_height) vidx = vhp.nonzero()[0] hidx = hhp.nonzero()[0] b = iulib.bytearray() iulib.extract_subimage(b, narray, int(vidx[0]), int(hidx[0]), int(vidx[-1]), int(hidx[-1])) return b
def get_lines_by_projection(narray, highpass=0.001): """Extract regions of blackness.""" hpr = iulib.numpy(narray).sum(axis=0) hps = high_pass_max(hpr, highpass) regions = [] gotline = None count = 0 for val in hps: if val != 0: if gotline is None: gotline = count else: if not gotline is None: regions.append((gotline, count)) gotline = None count += 1 return regions
def get_horizontal_projection(narray): """Accumulate image rows.""" return iulib.numpy(narray).sum(axis=0)
def get_vertical_projection(narray): """Accumulate image columns.""" return iulib.numpy(narray).sum(axis=1)