Convert raw to png

import numpy as np
import cv2
import scipy.misc


image_dir='./'

img_height = 604  #1208  #604 # Height of the model input images
img_width = 960    #1920   #960 # Width of the model input images
image_file = "./0.raw"

# read raw file
image = np.fromfile(image_file, dtype=np.float16)
print("raw image is:\n{}".format(image))
print("raw image size is:\n{}".format(image.size))
print("raw image shape is:\n{}".format(image.shape[0]))

image = np.reshape(image,[3,img_height, img_width]).astype(np.float32)
print("After reshpe to [3,height,width], image is:\n{}".format(image))
print("After reshpe to [3,height,width], image size is:\n{}".format(image.size))

image = image *255
image = np.transpose(image, (1, 2, 0))

# below two can work
#cv2.imwrite('test.png',image)
scipy.misc.imsave("foo.png", image)

  

posted on 2019-01-30 17:14  cdekelon  阅读(234)  评论(0)    收藏  举报

导航