Image processing 如何读取原始12图像并将其保存为可读格式-JPG、GIF、PNG

Image processing 如何读取原始12图像并将其保存为可读格式-JPG、GIF、PNG,image-processing,rgb,raw-file,Image Processing,Rgb,Raw File,正在寻找一个代码或操作系统库,使用Java/C/Python读取并保存为一些常用的格式-JPG、GIF、PNG。正在尝试以下代码: 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,

正在寻找一个代码或操作系统库,使用Java/C/Python读取并保存为一些常用的格式-JPG、GIF、PNG。正在尝试以下代码:

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)
发生异常:ValueError 无法将大小为9437184的数组重塑为形状20481536

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

尺寸2048、1536不正确在您的情况下,我尝试了3072*3072,结果如下:

将numpy作为np导入 将matplotlib.pyplot作为plt导入 输入文件=IT8-chart-5ms.raw12 npimg=np.fromfileinput\u文件,dtype=np.uint16 printnpimg.shape 图像大小=30723072 npimg=npimg.REGRAPEIMAGESIZE.astypenp.uint8 plt.imshownpimg,cmap='gray' plt.轴“关闭” 节目
第一部分非常简短,包含文件的规范。您可能只想实现它,它非常简单:仅3个简单项您可以丢弃第4个项感谢回答@Bilal,尝试使用python库,但出现异常,可能是因为RAW12是RGGB,如果您有更多线索,将不胜感激。感谢检查@Giacomo Catenazzi,我的备份计划确实是为了实现我自己的转换,也不知道如何从raw12拜耳模式RG/GB构建numpy阵列,如果您知道,请告诉我。