gpt4 book ai didi

python - Python中RAW图像的JPEG解压缩

转载 作者:行者123 更新时间:2023-12-01 01:45:11 25 4
gpt4 key购买 nike

当我尝试对 RAW 数据进行 JPEG 解压缩(旧式 JPEG 压缩,不是 JPEG-LS 也不是 JPEG2000)时,出现以下错误:

Traceback (most recent call last):
File "raw-reader.py", line 766, in <module>
raw_image_data = imageio.imread(io.BytesIO(raw_packed_image_data))
File "/home/ian/.local/lib/python3.6/site-packages/imageio/core/functions.py", line 206, in imread
reader = read(uri, format, 'i', **kwargs)
File "/home/ian/.local/lib/python3.6/site-packages/imageio/core/functions.py", line 129, in get_reader
return format.get_reader(request)
File "/home/ian/.local/lib/python3.6/site-packages/imageio/core/format.py", line 168, in get_reader
return self.Reader(self, request)
File "/home/ian/.local/lib/python3.6/site-packages/imageio/core/format.py", line 217, in __init__
self._open(**self.request.kwargs.copy())
File "/home/ian/.local/lib/python3.6/site-packages/imageio/plugins/pillow.py", line 398, in _open
pilmode=pilmode, as_gray=as_gray)
File "/home/ian/.local/lib/python3.6/site-packages/imageio/plugins/pillow.py", line 122, in _open
self._im = factory(self._fp, '')
File "/home/ian/.local/lib/python3.6/site-packages/PIL/JpegImagePlugin.py", line 780, in jpeg_factory
im = JpegImageFile(fp, filename)
File "/home/ian/.local/lib/python3.6/site-packages/PIL/ImageFile.py", line 102, in __init__
self._open()
File "/home/ian/.local/lib/python3.6/site-packages/PIL/JpegImagePlugin.py", line 339, in _open
handler(self, i)
File "/home/ian/.local/lib/python3.6/site-packages/PIL/JpegImagePlugin.py", line 166, in SOF
raise SyntaxError("cannot handle %d-bit layers" % self.bits)
SyntaxError: cannot handle 14-bit layers

图像中的RAW数据是14位JPEG数据,imageio无法读取它。当我尝试使用 Pillow 时,它甚至无法将数据识别为 JPEG。我现在的问题是:如何在不编写自己的 JPEG 解压缩器的情况下解压缩数据,同时记住数据是 14 位?

我的代码:

import io
import imageio

allbytes = open("raw_data.dat", "rb").read()

raw_packed_image_data = allbytes
raw_image_data = imageio.imread(io.BytesIO(raw_packed_image_data))

文件raw_data.dat是一个纯粹包含用JPEG压缩的RAW图像数据的文件。链接至raw_data.dat

最佳答案

raw_data.dat 是一个 JPEG 无损、非分层 文件,具有 2 帧且精度 > 8 位,是一种非常罕见的格式。

imagecodecs包可以读取该文件(假设存在 _imagecodecs Cython 扩展):

>>> from imagecodecs import jpegsof3_decode
>>> data = open('raw_data.dat', 'rb').read()
>>> image = jpegsof3_decode(data)
>>> image.shape
(3528, 2640, 2)
>>> image.dtype
dtype('uint16')

LEADTOOLS SDK 也应该能够读取该文件(未测试)。

关于python - Python中RAW图像的JPEG解压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51442437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com