added hysteresis thresholding function from Peter Kovesi