小编Otr*_*tri的帖子

将 32 位 TIFF 转换为 8 位 TIFF,同时保留 python 中的元数据和标签?

我想将多个具有 32 位像素深度的 TIFF 文件转换为 8 位像素深度 TIFF,同时保留元数据和 TIFF 标签

32 位 TIFF 是具有 TZYX 轴(即时间、z 深度、y 坐标、x 坐标)和 [0, 1] 范围内的值的四维 ImageJ 超级堆栈。

我可以转换为 8 位并复制元数据(使用在 ImageJ 中创建的非常小的示例图像):

import numpy as np
import tifffile

infile32 = "test.tif"

with tifffile.TiffFile(infile32) as tif:
    imagej_metadata = tif.imagej_metadata

a = tifffile.imread(infile32)
print(a.shape)

a = np.round(255 * a)
a = a.astype(np.uint8)

tifffile.imwrite("test_py-8bit.tif", a, imagej=True, metadata = imagej_metadata)
Run Code Online (Sandbox Code Playgroud)
>>> (4, 3, 10, 11)
Run Code Online (Sandbox Code Playgroud)

但是,像素分辨率(1 个像素有多少微米)错误,“z”轴 ( a.shape[1]) 被错误地识别为颜色通道,“时间”轴 (a.shape[0] ) 被错误地识别为 …

python tiff imagej imagej-hyperstack

5
推荐指数
1
解决办法
1067
查看次数

标签 统计

imagej ×1

imagej-hyperstack ×1

python ×1

tiff ×1