【问题标题】:What is the best way to load a CCITT T.3 compressed tiff using python?使用 python 加载 CCITT T.3 压缩 tiff 的最佳方法是什么?
【发布时间】:2010-07-28 18:06:07
【问题描述】:

我正在尝试将 CCITT T.3 压缩 tiff 加载到 python 中,并从中获取像素矩阵。它应该只是一个逻辑矩阵。

我尝试过使用 pylibtiff 和 PIL,但是当我用它们加载它时,它返回的矩阵是空的。我在很多地方读到这两个工具支持加载 CCITT 但不访问像素。

我愿意转换图像,只要我可以从中获取逻辑矩阵并在 python 代码中进行。疯狂的是,如果我在绘画中打开我的一张图像,保存它而不更改它,然后尝试用 pylibtiff 加载它,它就可以工作。 Paint 将其重新压缩为 LZW 压缩。

所以我想我真正的问题是:有没有办法将 CCITT 图像本地加载到矩阵或使用 python 将图像转换为 LZW?

谢谢,

泰勒米勒

【问题讨论】:

    标签: python compression tiff imaging image-formats


    【解决方案1】:

    似乎最好的方法是不完全使用 Python,而是依靠netpbm

    import Image
    import ImageFile
    import subprocess
    
    tiff = 'test.tiff'
    im = Image.open(tiff)
    print 'size', im.size
    try:
        print 'extrema', im.getextrema()
    except IOError as e:
        print 'help!', e, '\n'
    
    print 'I Get by with a Little Help from my Friends'
    pbm_proc = subprocess.Popen(['tifftopnm', tiff],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
    (pbm_data, pbm_error) = pbm_proc.communicate()
    ifp = ImageFile.Parser()
    ifp.feed(pbm_data)
    im = ifp.close()
    print 'conversion message', pbm_error,
    print 'extrema', im.getextrema()
    print 'size', im.size
    # houston: we have an image
    im.show()
    

    似乎可以解决问题:

    $ python g3fax.py 
    size (1728, 2156)
    extrema help! decoder group3 not available 
    
    I Get by with a Little Help from my Friends
    conversion message tifftopnm: writing PBM file
    extrema (0, 255)
    size (1728, 2156)
    

    【讨论】:

      【解决方案2】:

      如何运行tiffcpsubprocess转换为LZW(-c lzw开关),然后用pylibtiff正常处理?网络上有tiffcp 的Windows 版本。不完全是 Python 原生解决方案,但仍然...

      【讨论】:

      • 我尝试了 tiffcp,虽然它转换得很好,但图像仍然没有正确加载...虽然我不知道您可以转换为 lzw...我会试一试。 ..你能给我语法吗??
      • @tylerthemiler,没有特殊语法,只是tiffcp -c lzw from.tiff to.tiff。 msw 的回答有 subprocess 用法的例子。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      • 2017-08-30
      相关资源
      最近更新 更多