Working on an adaptive thresholding algorithm.