Correcting adaptive thresholding