Image types converter

Dear All,

Might be for some reason you want to convert the type of image exported from SNAP as float32 into to different type such us int16 or unit8, for this reason I wrote a piece of python code to implement so, please find the code following the below link,


How is the scaling handled?

Hi Marcus,

Briefly the model skimage works by dividing every value by the largest value possible by the image type, not the actual image itself, and then scale this by 255 to produced the normalized result, and provide it the type (dtype) of the image, ultimately obtain a structure of information for that type.

You should never use astype on an image, because it violates these assumptions about the dtype range:

from skimage.util import img_as_float
image = np.arange(0, 50, 10, dtype=np.uint8)
print(image.astype(float)) # These float values are out of range.
[ 0. 10. 20. 30. 40.]

[ 0. 0.03921569 0.07843137 0.11764706 0.15686275]