是否有Pythonic解决方案来读取和处理RAW图像。即使它只是访问一个原始的照片文件(例如,cr2或dng),然后将其输出为JPEG格式。Python中的RAW图像处理
理想情况下,一个用于python的dcraw绑定,但其他任何可以完成的东西也是足够的。
是否有Pythonic解决方案来读取和处理RAW图像。即使它只是访问一个原始的照片文件(例如,cr2或dng),然后将其输出为JPEG格式。Python中的RAW图像处理
理想情况下,一个用于python的dcraw绑定,但其他任何可以完成的东西也是足够的。
我不确定Python Imaging Imaging Library(PIL http://www.pythonware.com/products/pil/)中的RAW支持有多广泛,但您可能想检查一下。
否则,你可以直接调用dcraw,因为它已经很好地解决了这个问题。
尝试http://libopenraw.freedesktop.org/wiki/GettingTheCode
混帐回购协议: 的git://anongit.freedesktop.org/git/libopenraw.git
有一个在源代码树蟒目录。 ;-)
ImageMagick支持most RAW formats并提供Python bindings。
至于Python的dcraw绑定:dcraw是用C编写的,所以你可以通过ctypes
module来访问它。
我发现这个:https://gitorious.org/dcraw-thumbnailer/mainline/blobs/master/dcraw-thumbnailer
它要求Dcraw执行从蟒蛇的过程,并将其转换为PIL对象。
我写了一个纯python库,最近名为rawphoto
用于处理python中的原始图像。目前它只支持佳能CR2文件(我很快就会加入尼康格式)。它也在PyPi。如果您访问CR2文件,可能对您有所帮助。提取JPEG预览图像的
实施例:
from rawphoto.raw import Raw
# The API here will probably change before the 1.0 release.
blob = Raw(filename="somefile.CR2").fhandle.get_quarter_size_rgb()
# Do something with the JPEG here... eg. save it:
with open("output.jpeg", 'wb' as f:
f.write(blob)
EDIT:
from rawphoto.cr2 import Cr2
blob = Cr2(filename="somefile.CR2").get_quarter_size_rgb()
# Do something with the JPEG here... eg. save it:
with open("output.jpeg", 'wb' as f:
f.write(blob)
,或者使用通用Raw
类如添加更多,这将包装任何类型的原始文件的:这已被替换为rawkit,基于ctypes的libraw绑定。 RawKit将会更好地工作,您应该使用它(rawphoto现在将被弃用,并被用作教育工具)。
前一段时间我写了一个名为rawpy的libraw/dcraw包装器。这是很容易使用:
import rawpy
import imageio
raw = rawpy.imread('image.nef')
rgb = raw.postprocess()
imageio.imsave('default.tiff', rgb)
它与numpy的阵列原生支持,并支持大量的选项,包括直接访问未经处理的拜尔数据。
下面是佳能CR2图像转换为友好的格式与rawkit的方式,与目前的执行工作:
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')
使用numpy的阵列是不是很优雅在这里,但至少它的工作原理,我无法想象如何使用PIL构造函数来实现相同。
您正在保存jpeg格式的文件与PNG扩展。 – 2017-08-01 08:56:41
谢谢,修正了错字。 – 2017-08-02 13:02:06
PIL不做RAW(至少不是CR2或DCR)。 – Seth 2010-10-02 03:58:39