How to truncate the image values ??
Show older comments
How to truncate the image values so they stay in the [0 1] range
2 Comments
Asad Mirza
on 20 Feb 2019
This depends on what data type your image comes as. If it's a uint8 type then it's values will be from [0 255] but if you convert them to double with im2double then the values will range from [0 1].
Also, do you mean truncate as in set all values outside that range to 0?
Need some clarification.
ghada sandoub
on 21 Feb 2019
Accepted Answer
More Answers (1)
Jos (10584)
on 21 Feb 2019
X = randn(5,5)
a = 0, b = 1
% truncate values of X between a and b
Xt = min(max(X,a),b)
% scale values of X between a and b
Xsc = (X - min(X(:)) - a) .* b / range(X(:))
Categories
Find more on Morphological Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!