I'm trying to save a raw sensor buffer as a raw file using PIL. The buffer contains the CFA data (at 8-bit per pixel) and I'd like to save it as a raw CFA image that I'd be able to process later with and LibRaw (dcraw).
I've tried using PIL to save the image as a stream of bytes with .raw and .tiff suffix though it didn't work when I tried to load it.
When I load the image to numpy using imread, it seems that each pixel contains rgb (r=g=b) values.
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")