Image segmentation with adaptive thresholding