【问题标题】:How to read RAW 12 image and save it as some readable format - JPG, GIF, PNG如何读取 RAW 12 图像并将其保存为某种可读格式 - JPG、GIF、PNG
【发布时间】:2021-01-06 11:04:44
【问题描述】:

寻找代码或操作系统库以使用 Java / C# / Python 读取 RAW 12 并以一些常用格式保存 - 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 的数组重塑为形状 (2048,1536)

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

图像 RAW12 source

【问题讨论】:

  • 第一部分(非常短)包含文件的规范。你可能只想实现它(非常非常非常简单:只需 3 个简单项(你可以丢弃第 4 项)
  • 感谢@Bilal的回答,尝试使用python库,但出现异常,可能是因为RAW12是RGGB,如果您有更多线索,将不胜感激。
  • 感谢您检查此@Giacomo Catenazzi,我的备份计划确实是为了实现自己的转换,也不确定如何从 raw12 拜耳模式 RG/GB 构建 numpy 数组,如果您知道可以指出我将不胜感激.

标签: image-processing rgb raw-file


【解决方案1】:

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

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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 2019-10-22
    • 2014-03-27
    相关资源
    最近更新 更多