The threshold value at which the minimum increase in region size is observed while stepping down the threshold value will be the optimal threshold. In our program, the threshold value is decremented from 0.65 to 0.05 in steps of 0.1. If the minimum increase occurs when the threshold value was changed from 0.45 to 0.35, then the optimal threshold will be taken as 0.4.