Segmentation using thresholding using Python