def separate(polylines, f_mx_dist=<NUM_LIT:2>, mn_group_len=<NUM_LIT:4>):
s = []<EOL>for n in range(len(polylines) - <NUM_LIT:1>, -<NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>c = polylines[n]<EOL>separated = False<EOL>start = <NUM_LIT:0><EOL>for m in range(mn_group_len, len(c) - <NUM_LIT:1>):<EOL><INDENT>if m - start < mn_group_len:<EOL><INDENT>continue<EOL><DEDENT>m += <NUM_LIT:1><EOL>group = c[m - mn_group_len:m]<EOL>x, y = group[:, <NUM_LIT:0>], group[:, <NUM_LIT:1>]<EOL>asc, offs, _, _, _ = linregress(x, y)<EOL>yfit = asc * x + offs<EOL>p1 = c[m]<EOL>l = (x[<NUM_LIT:0>], yfit[<NUM_LIT:0>], p1[-<NUM_LIT:1>], asc * p1[-<NUM_LIT:1>] + offs)<EOL>std = np.mean([line.distance(l, g) for g in group])<EOL>dist = line.distance(l, p1)<EOL>if dist > <NUM_LIT:2> and dist > f_mx_dist * std:<EOL><INDENT>separated = True<EOL>s.append(c[start:m - <NUM_LIT:1>])<EOL>start = m - <NUM_LIT:1><EOL><DEDENT><DEDENT>if separated:<EOL><INDENT>if len(c) - start >= <NUM_LIT:2>:<EOL><INDENT>s.append(c[start:])<EOL><DEDENT>polylines.pop(n)<EOL><DEDENT><DEDENT>polylines.extend(s)<EOL>return polylines<EOL>
split polylines wherever crinkles are found