diff --git a/ocropus-gpageseg b/ocropus-gpageseg index 3b61ad4f..88d069a8 100755 --- a/ocropus-gpageseg +++ b/ocropus-gpageseg @@ -106,7 +106,11 @@ parser.add_argument('files',nargs='+') args = parser.parse_args() args.files = ocrolib.glob_all(args.files) - +def find(condition): + "Return the indices where ravel(condition) is true" + res, = np.nonzero(np.ravel(condition)) + return res + def norm_max(v): return v/np.amax(v) @@ -302,7 +306,7 @@ def compute_line_seeds(binary,bottom,top,colseps,scale): seeds = np.zeros(binary.shape,'i') delta = max(3,int(scale/2)) for x in range(bmarked.shape[1]): - transitions = sorted([(y,1) for y in np.where(bmarked[:,x])[0]]+[(y,0) for y in np.where(tmarked[:,x][0])])[::-1] + transitions = sorted([(y,1) for y in find(bmarked[:,x])]+[(y,0) for y in find(tmarked[:,x])])[::-1] transitions += [(0,0)] for l in range(len(transitions)-1): y0,s0 = transitions[l]