首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用JPEG压缩保存多通道(n > 3)图像(python)

使用JPEG压缩保存多通道(n > 3)图像(python)
EN

Stack Overflow用户
提问于 2020-04-11 00:05:21
回答 1查看 1K关注 0票数 0

我正在处理一些生物医学图像,有三个以上的频道。这些图像相当大,所以我倾向于将它们存储为金字塔式TIFF文件,并进行JPEG压缩。这给出了一个数量级压缩比与其他压缩方案(例如。LZW、Deflate)

目前,我正在使用pyvipstiffsave函数保存这些图像。使用其他压缩方案,我可以保存任意频道的图像。但是,通过JPEG压缩,我意识到保存的图像只能有一个或三个通道。

如果JPEG算法可以压缩一个通道,那么一定有办法将多个JPEG压缩的单通道图像打包到一个文件中吗?

有谁知道用以下条件将n>3通道图像存储到单个文件中的方法吗?

  • JPEG压缩(或具有类似性能的算法)
  • 使用图形用户界面图像查看软件(如ImageJ)很容易查看
  • 我真的不想把每个频道存储成一个单独的文件。
  • 以金字塔格式存储的图像
  • Python 3
EN

回答 1

Stack Overflow用户

发布于 2020-08-18 09:41:48

libvips 8.10现在出来了并支持OME金字塔的生成.

这些TIFF将每个通道存储在文件中的不同页面中,每个页面都有自己的金字塔保存在TIFF SUBIFD中。我希望ImageJ能读懂这些,尽管你可能需要一个插件。

您可以像这样在pyvips中生成它们:

代码语言:javascript
运行
复制
#!/usr/bin/python3

import sys
import pyvips

def load(filename):
    return pyvips.Image.new_from_file(filename)

# load a couple of eg. three-band images to make a 6-band image
image = load(sys.argv[2]).bandjoin(load(sys.argv[3]))

# to convert to OME, we need a tall, thin mono image with page-height set to
# indicate where the joins are
ome = pyvips.Image.arrayjoin(image.bandsplit(), across=1)

# you must make a private copy before modifying image metadata
ome = ome.copy()
ome.set_type(pyvips.GValue.gint_type, 'page-height', image.height)

# now we can write as a pyramid
# libvips 8.10+ will put the pyramid layers into SUBIFDs
ome.tiffsave(sys.argv[1], pyramid=True, compression="jpeg", Q=90)

像这样跑:

代码语言:javascript
运行
复制
$ ./gen_ome.py x.tif ~/pics/1.tiff ~/pics/2.tiff 
$ tiffinfo x.tif 
TIFF Directory at offset 0x173f02 (1523458)
  Subfile Type: multi-page document (2 = 0x2)
  Image Width: 6048 Image Length: 4032
  Tile Width: 128 Tile Length: 128
  Resolution: 300, 300 pixels/inch
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: JPEG
  Photometric Interpretation: min-is-black
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Planar Configuration: single image plane
  Page Number: 0-6
  SubIFD Offsets: 2153288 2339670 2396406 2415400 2422262 2424960
  JPEG Tables: (73 bytes)
TIFF Directory at offset 0x3c3b2c (3947308)
  Subfile Type: multi-page document (2 = 0x2)
  Image Width: 6048 Image Length: 4032
  Tile Width: 128 Tile Length: 128
...

所以你可以看到这六个通道有六个页面,每个页面都有一组包含金字塔层的SUBIFD。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61150448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档