【问题标题】:Python Pillow unknown RAW mode with 24 bit grayscal TIFF image具有 24 位灰度 TIFF 图像的 Python Pillow 未知 RAW 模式
【发布时间】:2021-01-27 21:35:59
【问题描述】:

我正在尝试使用 Pillow 在 Python 中将 24 位灰度 Tiff 图像转换为 JPEG。这种尝试适用于一些 24 位 Tiff 图像,但不是全部。它为下图提供unknown raw mode

from PIL import Image

im = Image.open("example.tif")
if im.mode != "L":  # rescale 16 bit tiffs to 8 bits
    im.mode = "I"
    im = im.point(lambda i: i * (1.0 / 256))
im = im.convert("RGB")
im.save("example.jpg", "JPEG", quality=100)

这是一个违规图片的示例(在上传到网站时似乎已转换为 PNG):

【问题讨论】:

    标签: python python-imaging-library jpeg tiff


    【解决方案1】:

    结果这个示例图像的模式已经是RGB,即使图像看起来是灰度的。如果您不先尝试手动重新缩放,枕头转换工作正常:

    from PIL import Image
    
    im = Image.open("example.tif")
    if im.mode not in ("L", "RGB"):  # rescale 16 bit tiffs to 8 bits
        im.mode = "L"
        im = im.point(lambda i: i * (1.0 / 256))
    im = im.convert("RGB")
    im.save("example.jpg", "JPEG", quality=100)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-25
      • 2011-09-19
      • 1970-01-01
      • 2020-10-11
      • 2013-01-06
      相关资源
      最近更新 更多