libvips 8.10 现已推出,支持生成 OME-TIFF 金字塔。
这些 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。