MATLAB: How to truncate the image values ?

truncate image values

How to truncate the image values so they stay in the [0 1] range

Best Answer

Truncate, or scale? There is a difference.
% Truncate:
yourImage(yourImage >1) = 1;
% Scale (min,max) to (0,1):
yourImage = mat2gray(yourImage);
% or scale max to 1, leaving min linearly scaled (not necessarily sent to 0).
yourImage = yourImage / max(yourImage(:))
Related Question