I'm writing some scripts in python that manipulate raw camera data. At the moment I'm using DCRAW to convert the information from the .nef (Nikon RAW format) file to a .tiff file and then converting it to an sRGB .png in photoshop so that I can use Pillow to read the pixel intensities.
Is there a way to parse the .nef file itself in python, instead of jumping through so many hoops?
I'm not concerned with speed, this is mostly a learning and demonstration exercise.
You might be able to make use of another library in combination with Pillow to achieve this task. For instance, rawpy
could do the job for you.
Their examples at the following link show how to read .nef
files and convert them to numpy arrays
using the postprocess()
method.
https://pypi.python.org/pypi/rawpy/0.3.5
From there you can easily save the images as TIFF or maybe do something like.
from PIL import Image
new_img = Image.fromarray(numpy_array)
Edit: I wrote a little script using rawpy and pillow that takes a .nef image, converts it into a numpy array, creates a new pillow image out of it, and shows it on the screen (obviously you can read intensities instead of showing it on the screen)
import rawpy
from PIL import Image
raw = rawpy.imread('trial.nef')
rgb = raw.postprocess()
img = Image.fromarray(rgb) # Pillow image
img.show() # show on screen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With