add gray image threshold function