RAW Image processing in Python [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question 开发者_运维知识库Are there any Pythonic solutions to reading and processing RAW images. Even if it's simply accessing a raw photo file (eg. cr2 or dng) and then outputting it as a jpeg.
Ideally a dcraw bindings for python, but anything else that can accomplish the came would be sufficient as well.
A while ago I wrote a libraw/dcraw wrapper called rawpy. It is quite easy to use:
import rawpy
import imageio
raw = rawpy.imread('image.nef')
rgb = raw.postprocess()
imageio.imsave('default.tiff', rgb)
It works natively with numpy arrays and supports a lot of options, including direct access to the unprocessed Bayer data.
ImageMagick supports most RAW formats and provides Python bindings.
As for dcraw bindings for Python: dcraw is written in C, so you can access it through ctypes
module.
Here is a way to convert a canon CR2 image to a friendly format with rawkit, that works with its current implementation:
import numpy as np
from PIL import Image
from rawkit.raw import Raw
filename = '/path/to/your/image.cr2'
raw_image = Raw(filename)
buffered_image = np.array(raw_image.to_buffer())
image = Image.frombytes('RGB', (raw_image.metadata.width, raw_image.metadata.height), buffered_image)
image.save('/path/to/your/new/image.png', format='png')
Using a numpy array is not very elegant here but at least it works, I could not figure how to use PIL constructors to achieve the same.
Try http://libopenraw.freedesktop.org/wiki/GettingTheCode
Git repo: git://anongit.freedesktop.org/git/libopenraw.git
There is a python directory in the source tree. ;-)
I'm not sure how extensive the RAW support in Python Imaging Library (PIL http://www.pythonware.com/products/pil/) is, but you may want to check that out.
Otherwise, you could just call dcraw directly since it already solves this problem nicely.
I found this: https://gitorious.org/dcraw-thumbnailer/mainline/blobs/master/dcraw-thumbnailer
It calls dcraw as a process from python and converts it to a PIL object.
精彩评论