将原始CFA缓冲区保存到原始图像

时间:2020-01-13 08:54:58

标签: python python-imaging-library imaging libraw dcraw

我正在尝试使用PIL将原始传感器缓冲区另存为原始文件。 该缓冲区包含CFA数据(每像素8位),我想将其保存为原始CFA图像,以后可以使用LibRaw(dcraw)处理。

我尝试使用PIL将图像保存为带有.raw和.tiff后缀的字节流,尽管在尝试加载它时不起作用。

当我使用imread将图像加载到numpy时,似乎每个像素都包含rgb(r = g = b)值。

    def process_raw_string(input_image):

    with open(input_image, mode='rb') as file:
        file_content = file.read()

    treated_buffer=bytearray(file_content)

    f = open('data.raw', 'w+b')
    binary_format = bytearray(treated_buffer)
    f.write(binary_format)
    f.close()

    img = Image.frombuffer("P", (3328,496), treated_buffer, 'raw', "P", 0, 1)
    img.convert('L').save("rawgrayscale.tiff")

0 个答案:

没有答案