【问题标题】:JPEG decompression in python3python3中的JPEG解压
【发布时间】:2018-07-19 17:53:56
【问题描述】:

我目前正在创建一个 TIFF 文件阅读器。为此,我需要实现 JPEG 解压缩,以便显示 JPEG 压缩图像。我一直在寻找 python3 的库来执行此操作,但我似乎找不到任何东西。这是我的代码:

zipped_image_data = read(image_tags[279][0]) #compressed image data
comp = image_tags[259][0] #compression type
width = image_tags[256][0] #image width
height = image_tags[257][0] #image height
channels = len(image_tags[258]) #amount of color channels

image_data = bytes()
if comp == 1:
    image_data = zipped_image_data
if comp == 8:
    image_data = zlib.decompress(zipped_image_data)
if comp == 6:
    print("jpeg decompress")

有很多方法可以解压 JPEG 图像文件,但我需要一些方法来仅将数据解压缩为字节。

感谢任何帮助!

【问题讨论】:

标签: python python-3.x jpeg binary-data compression


【解决方案1】:

我设法通过使用 io 模块解决了这个问题,它让我可以像访问文件一样访问字节。然后我可以解码这个“文件”并得到未压缩的数据:

like = io.BytesIO(zipped_image_data)
image_data = imageio.imread(like)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 1970-01-01
    • 2011-08-09
    相关资源
    最近更新 更多