4

I'm very new to working with the Raspberry Pi. For a project, I must have the raw images taken by the camera instead of the processed JPEGs. If I take a raw image using:

raspistill -r -o test.jpg

then how do I extract the raw image from test.jpg or process test.jpg to give me a readable raw file (.raw) back? I've seen many solutions online, but either they haven't worked for me or I don't know how to use them.

2
  • What methods did you use, and how did they fail?
    – Bex
    Commented Jul 26, 2017 at 6:43
  • The raw bayer captures recipe in the picamera docs goes through the basics (and should be sufficient for your case if you simply load test.jpg instead of capturing it). For more detail (dealing with rotation, camera modes etc.) see the PiBayerArray source
    – Dave Jones
    Commented Jul 26, 2017 at 20:37

1 Answer 1

2

In Python you can use https://github.com/OsmoSystems/picamraw/ to extract the raw Bayer data or a rudimentary demosaiced RGB image. The result is a numpy array that you can use with a variety of other python tools. This basic example should display the raw image:

First, install matplotlib and picamraw with pip install matplotlib picamraw.

Then, import the code, grab the bayer array, convert it to RGB and display it:

from matplotlib import pyplot as plt
import picamraw

raw_bayer = picamraw.PiRawBayer(
    filepath='path/to/image.jpeg',
    camera_version=picamraw.PiCameraVersion.V2,
)

plt.imshow(raw_bayer.to_rgb())

Full disclosure: my team just released that package. Let us know if you have any questions!

4
  • Current RPF images (using Raspbian Stretch) have the standard Python 3.5 installed. So people would have to kay their hands on a later version first. Probably need to compile it themselves. Not a great idea
    – Dirk
    Commented Dec 5, 2018 at 8:09
  • great point! We're mainly using it for offboard processing, so we focused on 3.6. Leaving out python 3.5 was an oversight. I just added 3.5 support, thanks for your feedback!
    – waterproof
    Commented Dec 5, 2018 at 20:48
  • Of course, in order to use matplotlib as in the example I provided, you'll have to have matplotlib set up with a functional backend. I haven't tested that onboard a pi.
    – waterproof
    Commented Dec 5, 2018 at 20:49
  • I have actually played around with matplotlib on a Pi running Raspbian Stretch w Python 3.5, so I think that should be OK
    – Dirk
    Commented Dec 5, 2018 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.