def hysterisis(edge, HT=100, LT=30):
    (H, W) = edge.shape
    edge[(edge >= HT)] = 255
    edge[(edge <= LT)] = 0
    _edge = np.zeros(((H + 2), (W + 2)), dtype=np.float32)
    _edge[1:(H + 1), 1:(W + 1)] = edge
    nn = np.array(((1.0, 1.0, 1.0), (1.0, 0.0, 1.0), (1.0, 1.0, 1.0)), dtype=np.float32)
    for y in range(1, (H + 2)):
        for x in range(1, (W + 2)):
            if ((_edge[(y, x)] < LT) or (_edge[(y, x)] > HT)):
                continue
            if (np.max((_edge[(y - 1):(y + 2), (x - 1):(x + 2)] * nn)) >= HT):
                _edge[(y, x)] = 255
            else:
                _edge[(y, x)] = 0
    edge = _edge[1:(H + 1), 1:(W + 1)]
    return edge
def hysterisis(edge, HT=100, LT=30):
    (H, W) = edge.shape
    edge[(edge >= HT)] = 255
    edge[(edge <= LT)] = 0
    _edge = np.zeros(((H + 2), (W + 2)), dtype=np.float32)
    _edge[1:(H + 1), 1:(W + 1)] = edge
    nn = np.array(((1.0, 1.0, 1.0), (1.0, 0.0, 1.0), (1.0, 1.0, 1.0)), dtype=np.float32)
    for y in range(1, (H + 2)):
        for x in range(1, (W + 2)):
            if ((_edge[(y, x)] < LT) or (_edge[(y, x)] > HT)):
                continue
            if (np.max((_edge[(y - 1):(y + 2), (x - 1):(x + 2)] * nn)) >= HT):
                _edge[(y, x)] = 255
            else:
                _edge[(y, x)] = 0
    edge = _edge[1:(H + 1), 1:(W + 1)]
    return edge