How to truncate the image values ??
5 次查看(过去 30 天)
显示 更早的评论
How to truncate the image values so they stay in the [0 1] range
2 个评论
Asad Mirza
2019-2-20
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.
采纳的回答
Image Analyst
2019-2-21
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(:))
0 个评论
更多回答(1 个)
Jos (10584)
2019-2-21
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(:))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modify Image Colors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!