使用 tifffile 一次写入一页(在示例中为 CTYX 多页),如果您有足够的 RAM 使用 tifffile.imwrite(filename,array)
https://pypi.org/ ,则可以直接从 nD 数组写入项目/tifffile/:
import tifffile as tf
with tf.TiffWriter("filenametest.tiff",
#bigtiff=True,
#If you want to add on top of an existing tiff file (slower) uncomment below
#append = True,
imagej=False,) as tif:
for time in range(rgb.shape[1]):
tif.save(rgb[:,time,:,:].,
#compress= 3,
photometric='minisblack',
metadata= None,
contiguous=False,
)
tif.close()
使用 python-bioformats:
https://pythonhosted.org/python-bioformats/
bioformats.write_image(pathname, pixels, pixel_type, c=0, z=0, t=0, size_c=1, size_z=1, size_t=1, channel_names=None)[source]
如果你有:
这应该可以解决问题
import bioformats as bf
import numpy as np
#do something here to load a,b,c, and d
i=0
for t in [a,b,c,d]:
for c in range(3):
for z in range(11):
#t here is the numpy array
bf.write_image('/path/to/file.tiff'
, t
, bf.PT_UINT16
, c = c, z = z , t = i, size_c= 3, size_z=11, size_t=4
)
i+=1