Search code examples
arraysmatplotlibtypesimread

matplotlib imread return an array of unit8, how to convert it to an array of float32?


Here's my code:

import matplotlib.pyplot as plt
img = plt.imread(<some image path>)

The img now is an array with dtype = unit8. How can I convert it into an array with dtype = float32?

Thanks!


Solution

  • Use ndarray.astype:

    img.astype('float32')