How to save a 3 channel numpy array as image

后端 未结 3 1651
借酒劲吻你
借酒劲吻你 2020-12-10 06:35

I have a numpy array with shape (3, 256, 256) which is a 3 channel (RGB) image of resoulution 256x256. I am trying to save this to disk with Image

3条回答
  •  旧时难觅i
    2020-12-10 06:48

    You can use opencv to do merge three channel and save as img.

    import cv2
    import numpy as np
    arr = np.random.uniform(size=(3,256,256))*255 # It's a r,g,b array
    img = cv2.merge((arr[2], arr[1], arr[0]))  # Use opencv to merge as b,g,r
    cv2.imwrite('out.png', img) 
    

提交回复
热议问题