我正在处理一些生物医学图像,有三个以上的频道。这些图像相当大,所以我倾向于将它们存储为金字塔式TIFF文件,并进行JPEG压缩。这给出了一个数量级压缩比与其他压缩方案(例如。LZW、Deflate)
目前,我正在使用pyvips
的tiffsave
函数保存这些图像。使用其他压缩方案,我可以保存任意频道的图像。但是,通过JPEG压缩,我意识到保存的图像只能有一个或三个通道。
如果JPEG算法可以压缩一个通道,那么一定有办法将多个JPEG压缩的单通道图像打包到一个文件中吗?
有谁知道用以下条件将n>3通道图像存储到单个文件中的方法吗?
发布于 2020-08-18 09:41:48
libvips 8.10现在出来了并支持OME金字塔的生成.
这些TIFF将每个通道存储在文件中的不同页面中,每个页面都有自己的金字塔保存在TIFF SUBIFD中。我希望ImageJ能读懂这些,尽管你可能需要一个插件。
您可以像这样在pyvips中生成它们:
#!/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)
像这样跑:
$ ./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。
https://stackoverflow.com/questions/61150448
复制相似问题