I have an image with data type int16.
So when I have to convert its range to 0-255, I got two ways to do that in Python.
1) Use numpy.uint8 function directly
2) Use OpenCV cv2.normalize function with 0-255 range and then use numpy.uint8.
In Matlab, we directly get the conversion using uint8 function.
In
Also in second case, I used NORM_MINMAX and the range of intensity values gets changed to 0-4.
What is the correct way to do the conversion?
解决方案
All of these do different things.
np.uint8 considers only the lowest byte of your number. It's like doing value & 0xff.
>>> img = np.array([2000, -150, 11], dtype=np.int16)
>>> np.uint8(img)
array([208, 106, 11], dtype=uint8)
cv2.normalize with the cv2.NORM_MINMAX norm type normalises your values accord