From my understanding, you want to convert your image to an image having its values in the range [0,1] or [0,255].
The mat2gray function is used to convert a matrix into a grayscale image whose values are in the range [0,1].
The following answer from the community may help you to convert the image values to the range [0,255].
The following link addresses the second part of your question regarding how to identify the image format.