1

I have an numpy array of size 2592 x 1944, and I want to save it as raw file format like ".nef" or ".raw". I wonder if there is any package or sample code to do this.

I see people asking related questions here How to save numpy array as .raw image? and someone suggestted using RawPy. However, after looking at RawPy I think it only allows opening a raw image and return the m x n array, which is exactly opposite to what I want to do (save a m x n array into raw image)

Thank you so much for helping!

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • What would be the point of doing that, please? – Mark Setchell Dec 07 '21 at 15:51
  • 1
    do you mean "raw" as in the photography file type, or just a bunch of bytes in a file, without any headers? dumping numpy arrays to file as binary data is well documented and explained. – Christoph Rackwitz Dec 07 '21 at 16:03
  • For the purpose, we are some physicists working on simulating the image of cosmic ray particles in cell phone CMOS, and in order to convert the deposited charge on pixels into image, we plan to first use a QDC convertor model to get the raw image and then work on the raw image using some well-developped post image processing software. Currently we plan to use https://www.darktable.org/ – Patchouli_goo Dec 07 '21 at 16:56
  • As for the definition of "raw", in fact we just want to convert the 2592 x 1944 pulse on pixel map into some file format that our image processing software can read in and do some Bayer interpolation, white balance, ... etc. It seems that it supports: RAW, NEF, RW1, RW2, ..... so anyone will be fine. I tried to save it as binary file with .nef end but it cannot be read into the software. I wonder if this is due to some missing metadata – Patchouli_goo Dec 07 '21 at 16:59
  • If there is any other recommended post image processing software that could take a m x n numpy array and do some bayer interpolation and post processings, then please let us know. Thanks! – Patchouli_goo Dec 07 '21 at 17:04
  • Do you mean a raw file of just your pixel intensities, without width, without height, without calibration data or embedded comments, copyright or datestamp? If so, and you have a single-channel 2592x1944 Numpy array of np.uint8 values, you will get a 5038848 byte raw file if you write `yourNumpyArray.tobytes()` into a file opened in binary mode. – Mark Setchell Dec 08 '21 at 22:56
  • Thanks for the help! If so, what is the file format I should use in order for it to be readable by raw image processing softwares like rawpy? or I have to add those info, like height, calibration data, copyright ...... in order to do so? – Patchouli_goo Dec 09 '21 at 02:50

0 Answers0