Modified the contour segmentation method to not crash when no threshold value is found.