Segmentation by setting gray threshold