MATLAB: Convert the intensity of image into a specific intensity range

digital image processingimage analysisimage processingImage Processing Toolbox

Hello everybody,
I have 100 3D medical images that have different intensity ranges. most of them have a maximum intensity of 255( and their type is single) but that of some of them is about 2000-3000( uint16). How can I convert the intensity of all images into [0,255]?
I tried this: 255*( (Img – min(Img(:)))./max(img(:))) but it didn't give the expected result. please help me with this problem.
Thank you.

Best Answer

You can use mat2gray:
Img2 = uint8(255 * mat2gray(Img));
or you can use rescale
Img2 = rescale(Img, 0, 255);
rescale gives a floating point output. Cast to uint8 if you want uint8. Pick whatever min and max you want. We can give a better answer if you tell us why the code you used did not give the expected answer.