def choose_gaps(im, wv, signal_per_pixel=0.0, max_dist=60, max_angle=(pi / 4.0)):
    (left, right) = group_ends(list(filter_ends(wv, 100, im.shape)))
    theta = (lambda w, side: reduce(arctan2, reversed(end_direction(w, side))))
    dtheta = (lambda left, right: fabs((theta(left, 0) - theta(right, (- 1)))))
    for (i, a) in enumerate(left):
        for (j, b) in enumerate(right):
            dx = (a.x[0] - b.x[(- 1)])
            dy = (a.y[0] - b.y[(- 1)])
            d = hypot(dx, dy)
            dth = dtheta(a, b)
            v = end_direction(a, 0)
            norm = hypot(*v)
            proj = dot((v / norm), (dx, dy))
            jth = fabs(arctan2(hypot(*((dx - ((proj * v[0]) / norm)), (dy - ((proj * v[1]) / norm)))), proj))
            l = 0
            if ((d < max_dist) and (jth < max_angle) and (proj > 0)):
                (px, py) = solve_polynomial_join(b, a)
                l = compute_join_score(im, px, py)
                if (l < (- signal_per_pixel)):
                    print(('\tScore: %g Theta: %g' % (l, ((jth * 180) / pi))))
                    e = make_joining_whisker(px, py, d, b.thick[(- 1)], b.scores[(- 1)], a.thick[0], a.scores[0])
                    (yield ((b, e, a), l))
def choose_gaps(im, wv, signal_per_pixel=0.0, max_dist=60, max_angle=(pi / 4.0)):
    (left, right) = group_ends(list(filter_ends(wv, 100, im.shape)))
    theta = (lambda w, side: reduce(arctan2, reversed(end_direction(w, side))))
    dtheta = (lambda left, right: fabs((theta(left, 0) - theta(right, (- 1)))))
    for (i, a) in enumerate(left):
        for (j, b) in enumerate(right):
            dx = (a.x[0] - b.x[(- 1)])
            dy = (a.y[0] - b.y[(- 1)])
            d = hypot(dx, dy)
            dth = dtheta(a, b)
            v = end_direction(a, 0)
            norm = hypot(*v)
            proj = dot((v / norm), (dx, dy))
            jth = fabs(arctan2(hypot(*((dx - ((proj * v[0]) / norm)), (dy - ((proj * v[1]) / norm)))), proj))
            l = 0
            if ((d < max_dist) and (jth < max_angle) and (proj > 0)):
                (px, py) = solve_polynomial_join(b, a)
                l = compute_join_score(im, px, py)
                if (l < (- signal_per_pixel)):
                    print(('\tScore: %g Theta: %g' % (l, ((jth * 180) / pi))))
                    e = make_joining_whisker(px, py, d, b.thick[(- 1)], b.scores[(- 1)], a.thick[0], a.scores[0])
                    (yield ((b, e, a), l))