Adaptive thresholding algorithms