Adaptive thresholding technique