the conversion issue for using img_as_float

569 views Asked by At

There is a multi-dimensional array to store images, e.g., imgs is of shape (512,512). Its dtype is float64 while the maximum value is 255.0, the minimum value is 0.0. I am trying to scale it to 0 and 1.

I used new_imgs = img_as_float(imgs). However, I found that the maximum value of new_imgs is still 255.0. In other words, it fails to scale the pixel values to 1. This seems to be contradict to what API documents describe:

enter image description here

1

There are 1 answers

1
J. P. Petersen On BEST ANSWER

It seems that img_as_float does not modify the numbers if the image is already given in a float type, see issue here.

Instead you could divide the values in the image by 255.0, to get them from [0; 255] to lie between [0; 1].