RAW Image processing in Python [closed]

丶灬走出姿态 提交于 2019-11-29 01:28:12

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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. ;-)




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/2422050/raw-image-processing-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!