Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a numpy array of floats into an image?

I have a opencv image variable called result. The shape of the array is (28800, 3) & has the following values

[[-9.10972506e-02 -9.10972506e-02 -9.10972506e-02]
 [-1.03304401e-01 -1.03304401e-01 -1.03304401e-01]
 [-1.05187558e-01 -1.05187558e-01 -1.05187558e-01]
...
 [-1.05294801e-01 -1.05294801e-01 -1.05294801e-01]
 [-1.06410049e-01 -1.06410049e-01 -1.06410049e-01]
 [-1.04490273e-01 -1.04490273e-01 -1.04490273e-01]
 [-7.67669156e-02 -7.67669156e-02 -7.67669156e-02]]
... You get the idea

I converted this to an RGB image format by using this.

result = result.reshape(( 144 ,  200, 3 ) )

These values are too small & get converted to int 0. How can I convert this to an image that is actually visible & understandable?

Thanks!

like image 923
Kabir Sharma Avatar asked Oct 22 '25 19:10

Kabir Sharma


1 Answers

Multiply the float values by 255 and cast them to uint8

new = np.multiply(result.reshape((144,  200, 3)), 255).astype(np.uint8)
like image 50
Nicolas Gervais Avatar answered Oct 24 '25 08:10

Nicolas Gervais