Can I save a numpy array as a 16-bit image using “normal” (Enthought) python?

后端 未结 5 1727
抹茶落季
抹茶落季 2020-12-03 12:15

Is there any way to save a numpy array as a 16 bit image (tif, png) using any of the commonly available python packages? This is the only way that I could get to work in the

5条回答
  •  鱼传尺愫
    2020-12-03 12:50

    As mentioned, PyPNG is very useful. For Enthought users it can be installed as e.g.:

    conda install -c eaton-lab pypng
    

    I'd use the from_array method of the shelf:

    import png
    import numpy as np
    
    bit_depth = 16
    
    my_array = np.ones((800, 800, 3)) 
    
    png.from_array(my_array*2**bit_depth-1, 'RGB;%s'%bit_depth).save('foo.png')
    

    Mode uses PIL style format, e.g. 'L', 'LA', 'RGB' or 'RGBA', followed by ';16' or ';8' too set bit depth. If bit depth is omitted, the dtype of the array is used.

    Read more here.

提交回复
热议问题