How to truncate the image values ??

조회 수: 3 (최근 30일)
ghada sandoub
ghada sandoub 2019년 2월 20일
답변: Jos (10584) 2019년 2월 21일
How to truncate the image values so they stay in the [0 1] range
  댓글 수: 2
Asad Mirza
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.
ghada sandoub
ghada sandoub 2019년 2월 21일
thanks for your comment. I'm following an algorithm for image enhancement and after applying the algorithm, the output is an image of type double and it needs simple modification to be more visual. the last step in the algorithm is to truncate the image to [0 1], which is of paramount
importance to improve the brightness and contrast of the image. but i don't know how to truncate the image. can you help me on that?? thanks

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
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(:))

추가 답변 (1개)

Jos (10584)
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(:))

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by