I have some array, let's say a = np.asarray([[10, 50], [30, 60]])
And I know that colors of pixels are colors = np.asarray([['G', 'R'], ['B', 'G']])
I want to save the image in .raw (or .dng) format. How do I do this?
Asked
Active
Viewed 2,947 times
5

samquar
- 155
- 2
- 8
-
Could you be a bit clearer about what your numbers in your array are please? Is it supposed to be a 2x2 pixel? What is the 10 please? 10 what? A sample image where the height, width and number of colour channels are all different is much easier to understand than a 2x2 pixel 2-channel image! – Mark Setchell Mar 26 '20 at 13:48
-
Why do you want to save this as DNG? DNG is an extremely portable, expressive format for high-resolution and non-standard data that often requires sophisticated deBayering and calibration. Is that your data? Or do you mean you want raw pixels without headers or other extraneous info? What are hou you trying to achieve here please? – Mark Setchell Mar 26 '20 at 13:52
-
@mark-setchell I have raw files but they saved for unknown me reason in png files. Basically they are like white-black pictures, but actually they are raw files. And I need to do demosaicing for them, but I can't open them in for example rawpy library. First array in my answer `a` is 2x2 picture, and each number corresponds to how much color of corresponding colors of `colors` is presented in the corresponding pixel – samquar Mar 26 '20 at 14:58
-
I'm confused. The title of your question implies you want to **write** a raw file, but your comment implies you have raw files, which are somehow PNG files, that you cannot **read**. Your 2-channel 2x2 pixel isn't helping much either. – Mark Setchell Mar 26 '20 at 15:12
-
@mark-setchell I read PNG files, I get some let's say 512x512 one channel numpy array. Then, I want to write this array to .raw file. I assume that Bayer filter is `[['G', 'R'], ['B', 'G']]` – samquar Mar 26 '20 at 16:35
-
You said they were colour files, but now you say they are single channel? – Mark Setchell Mar 26 '20 at 16:39
-
How about sharing the input file so we can see if it is raw or PNG, or single channel or colour? And also providing a link to a web page that describes the type of raw file you want to make, please? – Mark Setchell Mar 26 '20 at 16:42
-
I think, the answer is already [here](https://stackoverflow.com/questions/10535687/write-a-raw-binary-file-with-numpy-array-data/10536046#10536046?newreg=18c512a38c4e4db8bc74c29c3833709a). – Katerina Dudasova Apr 14 '21 at 14:51