-1

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

Genady
  • 25
  • 7
  • 1
    The first section (very short) contain the specification of the file. You may just want to implement it (it is very very very simple: just 3 simple items (you can discard the 4th item) – Giacomo Catenazzi Jan 06 '21 at 12:09
  • Thanks for answer @Bilal, tried to use python library, but getting exception, may be because RAW12 is RGGB, will appreciate if you have more clues. – Genady Jan 06 '21 at 14:45
  • Thanks for checking this @Giacomo Catenazzi, my backup plan indeed to implement myself conversion, also not sure how to build numpy array from raw12 bayer pattern RG/GB, will appreciate if you know can point me out. – Genady Jan 06 '21 at 15:35

1 Answers1

1

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()
Bilal
  • 3,191
  • 4
  • 21
  • 49