How to make a tiff z-stack conserving or adding metadata?

孤街浪徒 提交于 2019-12-11 02:53:54

问题


I have a number of tiff files that I would like to combine to a z-stack using python. The individual files have metadata that I would like to conserve (OME in my case), in particular the information on which z slice it is. Alternatively, I would like to insert somewhere in the z-stack's metadata that it is a z-stack (and not e.g. a time-lapse. I need this for opening the stacks correctly with Bioformats in ImageJ).

I can make a z-stack using e.g. tifffile.py, reading the individual files like in this simple example:

img1 = tifffile.imread(path_to_img1)
img2 = tifffile.imread(path_to_img2)
zstack = np.zeros((2, img1.shape[0], img1.shape[1]))
zstack[0] = img1
zstack[1] = img2
tifffile.imsave(path, zstack)

and I can also read the individual metadata information using tifffile.TiffFile.

However, I cannot see how to attach metadata for each slice. Tifffile has an option to add extra tags (including tag ID 270, the image description), but I don't understand how to apply this to each individual slice. On the other hand, the tifffile.TiffFile object has no write method.

I am not limited to tifffile and have also tried to use PIL, but have not succeeded.

来源:https://stackoverflow.com/questions/31978698/how-to-make-a-tiff-z-stack-conserving-or-adding-metadata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!