image gray levels and thresholding