Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
656 views
in Technique[技术] by (71.8m points)

rgb - How to read RAW 12 image and save it as some readable format - JPG, GIF, PNG

Looking for a code or OS library to read RAW 12 using Java / C# / Python and to save in some common used format - JPG, GIF, PNG. Trying a following code:

import numpy 
from PIL import Image
import rawpy

input_file = 'c:\IdeaProjects\raw12\IT8-chart-15ms.raw12'
npimg = numpy.fromfile(input_file, dtype=numpy.uint16)
imageSize = (2048, 1536)
npimg = npimg.reshape(imageSize)

Exception has occurred: ValueError cannot reshape array of size 9437184 into shape (2048,1536)

 output_file = 'converted.tiff'
 Image.fromarray(npimg/1023.0).save(output_file)

Image RAW12 source


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The dimensions (2048, 1536) are not correct in your case, I tried 3072*3072 and here is the result:

image

import numpy as np
import matplotlib.pyplot as plt 

input_file =  "IT8-chart-5ms.raw12"
npimg = np.fromfile(input_file, dtype=np.uint16)
# print(npimg.shape)
imageSize = (3072,3072)
npimg = (npimg.reshape(imageSize)).astype(np.uint8)

plt.imshow(npimg, cmap='gray')
plt.axis('off')
plt.show()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...