Gradient Based Image Segmentation Python Code