User avatar
schoolpost
Posts: 16
Joined: Sun Feb 19, 2017 10:47 am
Location: Canada
Contact: Website

Re: Pi Camera V2 raw bayer data

Fri Apr 14, 2017 6:06 am

Bryan I'm a little lost as to what you are aiming for.

You want to use the RAW information. You've mentioned DNG aswell. ( what camera version do you have? )

I very recently created a pretty simple to use python script to do this:
https://github.com/schoolpost/pydng

I believe it creates a pretty decent output in terms of color/quality and with the addition
of standard lossless DNG compression you can half the file size at no cost. Really cant get better than that.

The mentioned C tool will pack the RAW into a 16bit DNG. It works with both V1 and V2.
But lacks the correct color matrix and doesn't do any RAW calibration prior to packing it ( lens shading, hot pixel removal )

If you want to use the RAW data, do some debayering and then output into a more standard format you could possibly explore OpenCV debayer aswell.

Not to "inflate" or "hype" myself here, but in this situation I believe my aforementioned script above
will give you the best result if DNG is what you are after. Go ahead and tweak it as you see fit.
I realize too its not the most intuitive to work with, but should be quite workable.

I'm really trying to get the process done right, so feedback is very welcome.

perrociego
Posts: 14
Joined: Fri Jan 06, 2017 4:21 am

Re: Pi Camera V2 raw bayer data

Fri Apr 14, 2017 6:10 am

Hi Brian:

I tried the second code. It`s outputs is a .ppm without header. You may open it with Photoshop. 8 bits per color.

And I just tryng to understand the first one. Look quite good. It´s clear 16 bits.

8 bit´s vs 16 bit´s. Images wont look the same.
Attachments
Screen Shot 2017-01-28 at 19.44.19 copy.jpg
Photoshop options
Screen Shot 2017-01-28 at 19.44.19 copy.jpg (50.31 KiB) Viewed 1974 times

perrociego
Posts: 14
Joined: Fri Jan 06, 2017 4:21 am

Re: Pi Camera V2 raw bayer data

Fri Apr 14, 2017 6:21 am

Hi schoolpost:

Do you know how long does it take to your code to process an image?

Thanks for sharing

Marcelo

User avatar
schoolpost
Posts: 16
Joined: Sun Feb 19, 2017 10:47 am
Location: Canada
Contact: Website

Re: Pi Camera V2 raw bayer data

Fri Apr 14, 2017 7:52 am

perrociego wrote:Hi schoolpost:

Do you know how long does it take to your code to process an image?

Thanks for sharing

Marcelo
If you want to do a straight 16-bit DNG output it will take a 3-5 seconds.
( there's some processing going on with lens shading, hot pixel mapping. )
Its certainly not C level of speed / efficiency but good enough I would imagine for most applications.

I also have a 10-bit DNG output, that takes considerably longer as my method packing is a very crude, around 23 seconds.
It packs the 10-bit data like this:
AAAAAAAA AABBBBBB BBBBCCCC CCCCCCDD DDDDDDDD
This is needed for the pixel data to be read properly. ( kind of wish the RAW was originally packed this way :? )

This however once run through lossless compression will yield nearly half the uncompressed raw size.
16-bit will not achieve the same compression for obvious reasons.

If anyone knows how this packing could be improved its more than welcome. ( where rowData is a numpy rowslice of the bayer data )

Code: Select all

                count = 0
                rowPacked = []
                for i in range(0, len(rowData) + 1, 4):
                    if i != 0:
                        temp = ''
                        for k in rowData[count:i]:
                            temp += '{0:010b}'.format(k)
                        mask = 0
                        for j in range(0, 40 + 1, 8):
                            if j != 0:
                                rowPacked.append(int(temp[mask:j], 2))
                                mask = j
                        count = i
                self.wf.write(struct.pack('B' * len(rowPacked), *rowPacked))

Bryan See
Posts: 11
Joined: Mon Apr 10, 2017 2:33 pm

Re: Pi Camera V2 raw bayer data

Fri Apr 14, 2017 10:21 am

schoolpost wrote:Bryan I'm a little lost as to what you are aiming for.

You want to use the RAW information. You've mentioned DNG aswell. ( what camera version do you have? )

I very recently created a pretty simple to use python script to do this:
https://github.com/schoolpost/pydng

I believe it creates a pretty decent output in terms of color/quality and with the addition
of standard lossless DNG compression you can half the file size at no cost. Really cant get better than that.

The mentioned C tool will pack the RAW into a 16bit DNG. It works with both V1 and V2.
But lacks the correct color matrix and doesn't do any RAW calibration prior to packing it ( lens shading, hot pixel removal )

If you want to use the RAW data, do some debayering and then output into a more standard format you could possibly explore OpenCV debayer aswell.

Not to "inflate" or "hype" myself here, but in this situation I believe my aforementioned script above
will give you the best result if DNG is what you are after. Go ahead and tweak it as you see fit.
I realize too its not the most intuitive to work with, but should be quite workable.

I'm really trying to get the process done right, so feedback is very welcome.
I'm using camera version 2.1. IMX219.

User avatar
DougieLawson
Posts: 35381
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Pi Camera V2 raw bayer data

Fri Apr 14, 2017 2:29 pm

I get this

Code: Select all

(cheese:8868): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files

(cheese:8868): dconf-CRITICAL **: unable to create directory '/run/user/0/dconf': Permission denied.  dconf will not work properly.

(cheese:8868): dconf-CRITICAL **: unable to create directory '/run/user/0/dconf': Permission denied.  dconf will not work properly.
Failed to create secure directory (/run/user/0/pulse): Permission denied
Failed to create secure directory (/run/user/0/pulse): Permission denied
AL lib: (WW) alc_initconfig: Failed to initialize backend "pulse"
Failed to create secure directory (/run/user/0/pulse): Permission denied
Failed to create secure directory (/run/user/0/pulse): Permission denied
AL lib: (EE) alsa_open_capture: Could not open capture device 'default': No such file or directory

(cheese:8868): cheese-WARNING **: Could not open device.: gstopenalsrc.c(506): gst_openal_src_prepare (): /GstCameraBin:camerabin/GstAutoAudioSrc:audiosrc/GstOpenalSrc:audiosrc-actual-src-opena:
ALC error: Invalid Value


(cheese:8868): cheese-WARNING **: Internal data flow error.: gstbasesrc.c(2933): gst_base_src_loop (): /GstCameraBin:camerabin/GstAutoAudioSrc:audiosrc/GstOpenalSrc:audiosrc-actual-src-opena:
streaming task paused, reason not-negotiated (-4)
which looks to me like a bug in the Cheese programs.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

thatneat
Posts: 4
Joined: Tue Dec 04, 2018 5:52 pm

Re: Pi Camera V2 raw bayer data

Tue Dec 04, 2018 7:46 pm

This is a pretty old thread, but I thought folks reading it might be interested to know - in Python, my team just released a fork of picamera which pulls out the raw data from a raw+jpeg file into a more consumable, numpy format. It includes only the most basic demosaicing. Check out https://github.com/OsmoSystems/picamraw/

Return to “Camera board”